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_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)

Allocate an object of type "CInt":

Write a value to the raw memory:

Read the value:

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

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

Import the values of the raw memory as a list:

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:

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.

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_2024_rawmemoryallocate, author="Wolfram Research", title="{RawMemoryAllocate}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/RawMemoryAllocate.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_rawmemoryallocate, organization={Wolfram Research}, title={RawMemoryAllocate}, year={2023}, url={https://reference.wolfram.com/language/ref/RawMemoryAllocate.html}, note=[Accessed: 21-November-2024 ]}