RawMemoryExport[expr]
exports a raw memory representation of expr.
RawMemoryExport[expr,type]
uses the specified element type when returning an array.
RawMemoryExport
RawMemoryExport[expr]
exports a raw memory representation of expr.
RawMemoryExport[expr,type]
uses the specified element type when returning an array.
Details and Options
- RawMemoryExport returns a managed RawPointer object.
- type can be omitted if expr is a string, ByteArray or NumericArray.
- Possible element 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) - If expr is a ByteArray or a NumericArray, only integral and real types are allowed as the element type.
- The following options are supported:
-
CharacterEncoding "UTF-8" character encoding
Examples
open all close allBasic Examples (2)
Export a raw memory representation of an integer:
ptr = RawMemoryExport[-1, "CInt"]Read the contents of the pointer:
RawMemoryRead[ptr]Export a raw memory representation of a string:
ptr = RawMemoryExport["A string."]Import the contents of the raw memory:
RawMemoryImport[ptr, "String"]Scope (3)
Use the second argument of RawMemoryExport to specify the element type of the exported raw memory:
ptr = RawMemoryExport[-1, "CInt"];
ptr["Value"]["Type"]ptr = RawMemoryExport[-1, "CFloat"];
ptr["Value"]["Type"]The element type can be omitted if the exported expression is a string, a ByteArray or a NumericArray:
RawMemoryExport["A string."]RawMemoryExport[ByteArray[{1, 2, 3, 4, 5}]]RawMemoryExport[NumericArray[RandomReal[1, 4], "Real32"]]The raw memory is null-terminated when a string is exported:
ptr = RawMemoryExport["A string"];
RawMemoryImport[ptr, {"List", StringLength["A string"] + 1}]Options (1)
CharacterEncoding (1)
Specify what CharacterEncoding should be used when exporting a string:
str = "ÁÉÍÓÚ";
ptr1 = RawMemoryExport[str, CharacterEncoding -> "UTF-8"];
ptr2 = RawMemoryExport[str, CharacterEncoding -> "ISO8859-1"];Compare the contents of the pointers:
RawMemoryImport[ptr1, {"List", StringLength[str]}]RawMemoryImport[ptr2, {"List", StringLength[str]}]Properties & Relations (3)
By default, RawMemoryExport returns a RawPointer wrapped in ManagedObject:
ptr = RawMemoryExport[ByteArray[{1, 2, 3, 4, 5}]]Use UnmanageObject to unmanage the pointer:
UnmanageObject[ptr]RawMemoryImport is the inverse operation of RawMemoryExport:
ptr = RawMemoryExport["Some string."]RawMemoryImport[ptr, "String"]Use ForeignFunctionLoad to load a function that computes the sum of the elements of a raw memory:
sumArray = ForeignFunctionLoad["compilerDemoBase", "sumArray", {"RawPointer"::["CLong"], "CLong"} -> "CLong"]Export a list as a raw memory of "CLong" objects:
buffer = RawMemoryExport[Table[i, {i, 10}], "CLong"]Call the function by passing the buffer and its length:
sumArray[buffer, 10]Possible Issues (5)
Strings can only be exported as a raw memory of "UnsignedInteger8" objects:
RawMemoryExport["A string", "CFloat"]The element type of the raw memory cannot be automatically determined if the inputted expression is a list:
RawMemoryExport[{1, 2, 3}]Specify the target element type:
RawMemoryExport[{1, 2, 3}, "CInt"]RawMemoryExport will return $Failed if the element type is not supported:
RawMemoryExport[{1, 2, 3}, "UnsignedInteger18"]RawMemoryExport will return $Failed if an element does not match the specified element type:
RawMemoryExport[{1, -2, 3}, "UnsignedInteger8"]If the exported expression is a ByteArray or a NumericArray, the element type can only be integral and real types:
RawMemoryExport[ByteArray[{1, 2, 3}], "Void"]Tech Notes
Related Guides
History
Text
Wolfram Research (2023), RawMemoryExport, Wolfram Language function, https://reference.wolfram.com/language/ref/RawMemoryExport.html.
CMS
Wolfram Language. 2023. "RawMemoryExport." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RawMemoryExport.html.
APA
Wolfram Language. (2023). RawMemoryExport. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RawMemoryExport.html
BibTeX
@misc{reference.wolfram_2026_rawmemoryexport, author="Wolfram Research", title="{RawMemoryExport}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/RawMemoryExport.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_rawmemoryexport, organization={Wolfram Research}, title={RawMemoryExport}, year={2023}, url={https://reference.wolfram.com/language/ref/RawMemoryExport.html}, note=[Accessed: 13-June-2026]}