RawMemoryImport[ptr,format]
imports raw memory from the pointer ptr with the specified format.
RawMemoryImport[format]
represents an operator form of RawMemoryImport that can be applied to an expression.
RawMemoryImport
RawMemoryImport[ptr,format]
imports raw memory from the pointer ptr with the specified format.
RawMemoryImport[format]
represents an operator form of RawMemoryImport that can be applied to an expression.
Details and Options
- Supported values of ptr include RawPointer expressions and ManagedObject expressions whose values are pointers.
- Supported values of format include:
-
"String" null-terminated string {"String",len} string of len bytes {"ByteArray",len} byte array of len bytes {"NumericArray",len} numeric array of len elements {"List",len} list of len elements - For "NumericArray" and "List" import formats, the element type is determined by the type of the input pointer ptr.
- Supported options include:
-
CharacterEncoding "UTF-8" character encoding for strings
Examples
open all close allBasic Examples (1)
Scope (4)
RawMemoryImport supports passing a managed pointer as its first argument:
ptr = RawMemoryExport["A test."]RawMemoryImport[ptr, "String"]It also supports passing a non-managed pointer:
rawPtr = UnmanageObject@ptrRawMemoryImport[ptr, "String"]Export a string as raw memory:
str = "A string";
strLen = StringLength[str];
ptr = RawMemoryExport[str]Import the raw memory as a "List":
RawMemoryImport[ptr, {"List", strLen}]Import the raw memory as a "ByteArray":
RawMemoryImport[ptr, {"ByteArray", strLen}]Import the raw memory as a "NumericArray":
RawMemoryImport[ptr, {"NumericArray", strLen}]Export a string as a raw memory:
ptr = RawMemoryExport["A string"];For null-terminated strings, the length does not need to be specified:
RawMemoryImport[ptr, "String"]Use RawMemoryImport in operator form:
ptr = RawMemoryExport["A test."];
RawMemoryImport["String"][ptr]Options (1)
CharacterEncoding (1)
Export a string with non-ASCII characters as raw memory:
str = "ÁÉÍÓÚ";
ptr = RawMemoryExport[str];Specify what CharacterEncoding should be used when importing a string:
RawMemoryImport[ptr, "String", CharacterEncoding -> "ASCII"]RawMemoryImport[ptr, "String", CharacterEncoding -> "UTF-8"]Properties & Relations (1)
RawMemoryExport is the inverse operation of RawMemoryImport:
ptr = RawMemoryExport["Some string."]RawMemoryImport[ptr, "String"]Possible Issues (1)
RawMemoryImport fails if the format is not supported:
RawMemoryImport[RawMemoryExport["A test."], "ByteArray"]Tech Notes
Related Guides
History
Text
Wolfram Research (2023), RawMemoryImport, Wolfram Language function, https://reference.wolfram.com/language/ref/RawMemoryImport.html.
CMS
Wolfram Language. 2023. "RawMemoryImport." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RawMemoryImport.html.
APA
Wolfram Language. (2023). RawMemoryImport. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RawMemoryImport.html
BibTeX
@misc{reference.wolfram_2026_rawmemoryimport, author="Wolfram Research", title="{RawMemoryImport}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/RawMemoryImport.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_rawmemoryimport, organization={Wolfram Research}, title={RawMemoryImport}, year={2023}, url={https://reference.wolfram.com/language/ref/RawMemoryImport.html}, note=[Accessed: 13-June-2026]}