WOLFRAM

allocates enough raw memory to store a binary representation of the specified type.

RawMemoryAllocate[type,len]

allocates memory for len objects.

Details

  • RawMemoryAllocate returns a managed RawPointer object.
  • Possible types, and their corresponding C types, include:
  • "UnsignedInteger8"uint8_tunsigned 8-bit integer
    "Integer8"int8_tsigned 8-bit integer
    "UnsignedInteger16"uint16_tunsigned 16-bit integer
    "Integer16"int16_tsigned 16-bit integer
    "UnsignedInteger32"uint32_tunsigned 32-bit integer
    "Integer32"int32_tsigned 32-bit integer
    "UnsignedInteger64"uint64_tunsigned 64-bit integer
    "Integer64"int64_tsigned 64-bit integer
    "CUnsignedChar"unsigned charC-compatible unsigned char
    "CSignedChar"signed charC-compatible signed char
    "CUnsignedShort"unsigned shortC-compatible unsigned short
    "CShort"shortC-compatible short
    "CUnsignedInt"unsigned intC-compatible unsigned int
    "CInt"intC-compatible int
    "CUnsignedLong"unsigned longC-compatible unsigned long
    "CLong"longC-compatible long
    "CSizeT"size_tC-compatible size_t
    "CFloat"floatC-compatible float
    "CDouble"doubleC-compatible double
    "OpaqueRawPointer"void*opaque pointer
    "RawPointer"::[t]t*typed pointer
    {ty1,ty2,}struct {ty1 f1; ty2 f2; }struct or product type
    "Void"voidno output (only in output types)

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Allocate an object of type "CInt":

Out[1]=1

Write a value to the raw memory:

Read the value:

Out[3]=3

Allocate a raw memory of 10 objects of type "CFloat":

Out[1]=1

Initialize the raw memory with random numbers between 0 and 1:

Import the values of the raw memory as a list:

Out[3]=3

Properties & Relations  (3)Properties of the function, and connections to other functions

By default, RawMemoryAllocate returns a RawPointer wrapped in ManagedObject:

Out[1]=1

To unmanage the pointer, use UnmanageObject:

Out[2]=2

Call RawMemoryFree to free the unmanaged pointer:

Use RawMemoryWrite to write values to the raw memory:

RawMemoryRead reads the values stored in the raw memory:

Out[2]=2

Allocate a buffer of 10 "CLong" objects:

Out[1]=1

Use ForeignFunctionLoad to load a function that populates this buffer:

Out[2]=2

Call the function by passing the buffer and its length:

Import the raw memory as a list with RawMemoryImport:

Out[4]=4

Possible Issues  (2)Common pitfalls and unexpected behavior

RawMemoryAllocate will return $Failed if the type is not supported:

Out[1]=1

The number of allocated objects should be a positive integer:

Out[1]=1
Wolfram Research (2023), RawMemoryAllocate, Wolfram Language function, https://reference.wolfram.com/language/ref/RawMemoryAllocate.html.
Wolfram Research (2023), RawMemoryAllocate, Wolfram Language function, https://reference.wolfram.com/language/ref/RawMemoryAllocate.html.

Text

Wolfram Research (2023), RawMemoryAllocate, Wolfram Language function, https://reference.wolfram.com/language/ref/RawMemoryAllocate.html.

Wolfram Research (2023), RawMemoryAllocate, Wolfram Language function, https://reference.wolfram.com/language/ref/RawMemoryAllocate.html.

CMS

Wolfram Language. 2023. "RawMemoryAllocate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RawMemoryAllocate.html.

Wolfram Language. 2023. "RawMemoryAllocate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RawMemoryAllocate.html.

APA

Wolfram Language. (2023). RawMemoryAllocate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RawMemoryAllocate.html

Wolfram Language. (2023). RawMemoryAllocate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RawMemoryAllocate.html

BibTeX

@misc{reference.wolfram_2025_rawmemoryallocate, author="Wolfram Research", title="{RawMemoryAllocate}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/RawMemoryAllocate.html}", note=[Accessed: 25-March-2025 ]}

@misc{reference.wolfram_2025_rawmemoryallocate, author="Wolfram Research", title="{RawMemoryAllocate}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/RawMemoryAllocate.html}", note=[Accessed: 25-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_rawmemoryallocate, organization={Wolfram Research}, title={RawMemoryAllocate}, year={2023}, url={https://reference.wolfram.com/language/ref/RawMemoryAllocate.html}, note=[Accessed: 25-March-2025 ]}

@online{reference.wolfram_2025_rawmemoryallocate, organization={Wolfram Research}, title={RawMemoryAllocate}, year={2023}, url={https://reference.wolfram.com/language/ref/RawMemoryAllocate.html}, note=[Accessed: 25-March-2025 ]}