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

- RawMemoryAllocate returns a managed RawPointer object.
- Possible types, and their corresponding C types, include:
-
"UnsignedInteger8" uint8_t unsigned 8-bit integer "Integer8" int8_t signed 8-bit integer "UnsignedInteger16" uint16_t unsigned 16-bit integer "Integer16" int16_t signed 16-bit integer "UnsignedInteger32" uint32_t unsigned 32-bit integer "Integer32" int32_t signed 32-bit integer "UnsignedInteger64" uint64_t unsigned 64-bit integer "Integer64" int64_t signed 64-bit integer "CUnsignedChar" unsigned char C-compatible unsigned char "CSignedChar" signed char C-compatible signed char "CUnsignedShort" unsigned short C-compatible unsigned short "CShort" short C-compatible short "CUnsignedInt" unsigned int C-compatible unsigned int "CInt" int C-compatible int "CUnsignedLong" unsigned long C-compatible unsigned long "CLong" long C-compatible long "CSizeT" size_t C-compatible size_t "CFloat" float C-compatible float "CDouble" double C-compatible double "OpaqueRawPointer" void* opaque pointer "RawPointer"::[t] t* typed pointer {ty1,ty2,…} struct {ty1 f1; ty2 f2; …} struct or product type "Void" void no output (only in output types)
Examples
open allclose allBasic Examples (2)Summary of the most common use cases
Allocate an object of type "CInt":

https://wolfram.com/xid/0fq7nc8nm6cq7-2o7ot0

Write a value to the raw memory:

https://wolfram.com/xid/0fq7nc8nm6cq7-x04r7d

https://wolfram.com/xid/0fq7nc8nm6cq7-ehrpuk

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

https://wolfram.com/xid/0fq7nc8nm6cq7-klczv8

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

https://wolfram.com/xid/0fq7nc8nm6cq7-ieownp
Import the values of the raw memory as a list:

https://wolfram.com/xid/0fq7nc8nm6cq7-t44xur

Properties & Relations (3)Properties of the function, and connections to other functions
By default, RawMemoryAllocate returns a RawPointer wrapped in ManagedObject:

https://wolfram.com/xid/0fq7nc8nm6cq7-pnx687

To unmanage the pointer, use UnmanageObject:

https://wolfram.com/xid/0fq7nc8nm6cq7-4zay7p

Call RawMemoryFree to free the unmanaged pointer:

https://wolfram.com/xid/0fq7nc8nm6cq7-pid3yk
Use RawMemoryWrite to write values to the raw memory:

https://wolfram.com/xid/0fq7nc8nm6cq7-g4bb9o
RawMemoryRead reads the values stored in the raw memory:

https://wolfram.com/xid/0fq7nc8nm6cq7-4lcq5r

Allocate a buffer of 10 "CLong" objects:

https://wolfram.com/xid/0fq7nc8nm6cq7-bqm82s

Use ForeignFunctionLoad to load a function that populates this buffer:

https://wolfram.com/xid/0fq7nc8nm6cq7-ngv0o5

Call the function by passing the buffer and its length:

https://wolfram.com/xid/0fq7nc8nm6cq7-2in6km
Import the raw memory as a list with RawMemoryImport:

https://wolfram.com/xid/0fq7nc8nm6cq7-0o98hw

Possible Issues (2)Common pitfalls and unexpected behavior
RawMemoryAllocate will return $Failed if the type is not supported:

https://wolfram.com/xid/0fq7nc8nm6cq7-8ue6sr


The number of allocated objects should be a positive integer:

https://wolfram.com/xid/0fq7nc8nm6cq7-38xtf5


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
]}
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
]}