WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

RawMemoryExport [expr]

exports a raw memory representation of expr.

RawMemoryExport [expr,type]

uses the specified element type when returning an array.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Options  
CharacterEncoding  
Properties & Relations  
Possible Issues  
See Also
Tech Notes
Related Guides
History
Cite this Page

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 all

Basic Examples  (2)

Export a raw memory representation of an integer:

Wolfram Language code: ptr = RawMemoryExport[-1, "CInt"]

Read the contents of the pointer:

Wolfram Language code: RawMemoryRead[ptr]

Export a raw memory representation of a string:

Wolfram Language code: ptr = RawMemoryExport["A string."]

Import the contents of the raw memory:

Wolfram Language code: RawMemoryImport[ptr, "String"]

Scope  (3)

Use the second argument of RawMemoryExport to specify the element type of the exported raw memory:

Wolfram Language code: ptr = RawMemoryExport[-1, "CInt"]; ptr["Value"]["Type"]
Wolfram Language code: 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 :

Wolfram Language code: RawMemoryExport["A string."]
Wolfram Language code: RawMemoryExport[ByteArray[{1, 2, 3, 4, 5}]]
Wolfram Language code: RawMemoryExport[NumericArray[RandomReal[1, 4], "Real32"]]

The raw memory is null-terminated when a string is exported:

Wolfram Language code: 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:

Wolfram Language code: str = "ÁÉÍÓÚ"; ptr1 = RawMemoryExport[str, CharacterEncoding -> "UTF-8"]; ptr2 = RawMemoryExport[str, CharacterEncoding -> "ISO8859-1"];

Compare the contents of the pointers:

Wolfram Language code: RawMemoryImport[ptr1, {"List", StringLength[str]}]
Wolfram Language code: RawMemoryImport[ptr2, {"List", StringLength[str]}]

Properties & Relations  (3)

By default, RawMemoryExport returns a RawPointer wrapped in ManagedObject :

Wolfram Language code: ptr = RawMemoryExport[ByteArray[{1, 2, 3, 4, 5}]]

Use UnmanageObject to unmanage the pointer:

Wolfram Language code: UnmanageObject[ptr]

RawMemoryImport is the inverse operation of RawMemoryExport :

Wolfram Language code: ptr = RawMemoryExport["Some string."]
Wolfram Language code: RawMemoryImport[ptr, "String"]

Use ForeignFunctionLoad to load a function that computes the sum of the elements of a raw memory:

Wolfram Language code: sumArray = ForeignFunctionLoad["compilerDemoBase", "sumArray", {"RawPointer"::["CLong"], "CLong"} -> "CLong"]

Export a list as a raw memory of "CLong" objects:

Wolfram Language code: buffer = RawMemoryExport[Table[i, {i, 10}], "CLong"]

Call the function by passing the buffer and its length:

Wolfram Language code: sumArray[buffer, 10]

Possible Issues  (5)

Strings can only be exported as a raw memory of "UnsignedInteger8" objects:

Wolfram Language code: RawMemoryExport["A string", "CFloat"]

The element type of the raw memory cannot be automatically determined if the inputted expression is a list:

Wolfram Language code: RawMemoryExport[{1, 2, 3}]

Specify the target element type:

Wolfram Language code: RawMemoryExport[{1, 2, 3}, "CInt"]

RawMemoryExport will return $Failed if the element type is not supported:

Wolfram Language code: RawMemoryExport[{1, 2, 3}, "UnsignedInteger18"]

RawMemoryExport will return $Failed if an element does not match the specified element type:

Wolfram Language code: 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:

Wolfram Language code: RawMemoryExport[ByteArray[{1, 2, 3}], "Void"]

Tech Notes

Wolfram Research (2023), RawMemoryExport, Wolfram Language function, https://reference.wolfram.com/language/ref/RawMemoryExport.html.

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-August-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-August-2026]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /