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_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)
  • 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 allclose all

Basic Examples  (2)

Export a raw memory representation of an integer:

Read the contents of the pointer:

Export a raw memory representation of a string:

Import the contents of the raw memory:

Scope  (3)

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

The element type can be omitted if the exported expression is a string, a ByteArray or a NumericArray:

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

Options  (1)

CharacterEncoding  (1)

Specify what CharacterEncoding should be used when exporting a string:

Compare the contents of the pointers:

Properties & Relations  (3)

By default, RawMemoryExport returns a RawPointer wrapped in ManagedObject:

Use UnmanageObject to unmanage the pointer:

RawMemoryImport is the inverse operation of RawMemoryExport:

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

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

Call the function by passing the buffer and its length:

Possible Issues  (5)

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

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

Specify the target element type:

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

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

If the exported expression is a ByteArray or a NumericArray, the element type can only be integral and real types:

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

BibLaTeX

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