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 allclose allBasic Examples (2)
Properties & Relations (3)
By default, RawMemoryAllocate returns a RawPointer wrapped in ManagedObject:
To unmanage the pointer, use UnmanageObject:
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:
Allocate a buffer of 10 "CLong" objects:
Use ForeignFunctionLoad to load a function that populates this buffer:
Call the function by passing the buffer and its length:
Import the raw memory as a list with RawMemoryImport:
Possible Issues (2)
RawMemoryAllocate will return $Failed if the type is not supported:
The number of allocated objects should be a positive integer:
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