RawMemoryAllocate[type]
allocates enough raw memory to store a binary representation of the specified type.
RawMemoryAllocate[type,len]
allocates memory for len objects.
RawMemoryAllocate
RawMemoryAllocate[type]
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_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 all close allBasic Examples (2)
Allocate an object of type "CInt":
ptr = RawMemoryAllocate["CInt"]Write a value to the raw memory:
RawMemoryWrite[ptr, -1];RawMemoryRead[ptr]Allocate a raw memory of 10 objects of type "CFloat":
buffer = RawMemoryAllocate["CFloat", 10]Initialize the raw memory with random numbers between 0 and 1:
Do[RawMemoryWrite[buffer, RandomReal[], i], {i, 0, 9}]Import the values of the raw memory as a list:
RawMemoryImport[buffer, {"List", 10}]Properties & Relations (3)
By default, RawMemoryAllocate returns a RawPointer wrapped in ManagedObject:
ptr = RawMemoryAllocate["UnsignedInteger8"]To unmanage the pointer, use UnmanageObject:
rawPtr = UnmanageObject[ptr]Call RawMemoryFree to free the unmanaged pointer:
RawMemoryFree[rawPtr]Use RawMemoryWrite to write values to the raw memory:
ptr = RawMemoryAllocate["UnsignedInteger8"];
RawMemoryWrite[ptr, 255];RawMemoryRead reads the values stored in the raw memory:
RawMemoryRead[ptr]Allocate a buffer of 10 "CLong" objects:
buffer = RawMemoryAllocate["CLong", 10]Use ForeignFunctionLoad to load a function that populates this buffer:
populateArray = ForeignFunctionLoad["compilerDemoBase", "populateArray", {"RawPointer"::["CLong"], "CLong"} -> "CInt"]Call the function by passing the buffer and its length:
populateArray[buffer, 10];Import the raw memory as a list with RawMemoryImport:
RawMemoryImport[buffer, {"List", 10}]Possible Issues (2)
RawMemoryAllocate will return $Failed if the type is not supported:
RawMemoryAllocate["ByteArray"]The number of allocated objects should be a positive integer:
RawMemoryAllocate["UnsignedInteger8", 0]Tech Notes
Related Guides
History
Text
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.
APA
Wolfram Language. (2023). RawMemoryAllocate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RawMemoryAllocate.html
BibTeX
@misc{reference.wolfram_2026_rawmemoryallocate, author="Wolfram Research", title="{RawMemoryAllocate}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/RawMemoryAllocate.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_rawmemoryallocate, organization={Wolfram Research}, title={RawMemoryAllocate}, year={2023}, url={https://reference.wolfram.com/language/ref/RawMemoryAllocate.html}, note=[Accessed: 13-June-2026]}