RawPointer
✖
RawPointer
Details

- RawPointer is returned by functions such as ForeignFunction, RawMemoryAllocate, etc.
- Functions that allocate raw memory will return a memory-managed pointer.
- OpaqueRawPointer can be used to represent untyped pointers.
- RawPointer[ptr,type] can be used to cast a pointer to a typed pointer.
- Information for a RawPointer may include the following properties:
-
"Address" memory address "Type" referenced type - Properties of a RawPointer can be extracted with RawPointer[…][prop].
- Properties that can be extracted include all Information properties listed above.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Export a string as raw memory represented by a managed RawPointer:

https://wolfram.com/xid/0rs5u6a3a-cbzwp4


https://wolfram.com/xid/0rs5u6a3a-stb323

Write a value to the raw memory:

https://wolfram.com/xid/0rs5u6a3a-feaufq
Import the raw memory as a string:

https://wolfram.com/xid/0rs5u6a3a-2y6xxp


https://wolfram.com/xid/0rs5u6a3a-xo1vps
Scope (1)Survey of the scope of standard use cases
Information (1)
Create a pointer to raw memory:

https://wolfram.com/xid/0rs5u6a3a-foy396

Get Information about the pointer:

https://wolfram.com/xid/0rs5u6a3a-mffoz6

Get the memory address of the pointer:

https://wolfram.com/xid/0rs5u6a3a-j20rsp


https://wolfram.com/xid/0rs5u6a3a-jqd047

Properties & Relations (5)Properties of the function, and connections to other functions
Functions like RawMemoryAllocate return a memory-managed RawPointer:

https://wolfram.com/xid/0rs5u6a3a-t7oo94

Call UnmanageObject to take ownership of the managed pointer:

https://wolfram.com/xid/0rs5u6a3a-s4u1o3

Notice that the memory management of the pointer allocated is no longer active:

https://wolfram.com/xid/0rs5u6a3a-nym11z

Unmanaged pointers should be freed with RawMemoryFree to avoid memory leaks:

https://wolfram.com/xid/0rs5u6a3a-fpucx3
NullRawPointerQ returns True if a raw pointer has 0 as its address:

https://wolfram.com/xid/0rs5u6a3a-o7h4us


https://wolfram.com/xid/0rs5u6a3a-0ksk2u

Convert a RawPointer into an OpaqueRawPointer:

https://wolfram.com/xid/0rs5u6a3a-38texn

Convert the opaque raw pointer back to a RawPointer:

https://wolfram.com/xid/0rs5u6a3a-127kwl

Allocate a raw memory for an object of type "UnsignedInteger8":

https://wolfram.com/xid/0rs5u6a3a-5tx94m

Write a value to the raw memory by passing the pointer to RawMemoryWrite:

https://wolfram.com/xid/0rs5u6a3a-ltumwt

Read the raw memory with RawMemoryRead:

https://wolfram.com/xid/0rs5u6a3a-9me5i8

Allocate a buffer of 10 "CLong" objects:

https://wolfram.com/xid/0rs5u6a3a-bqm82s

Use ForeignFunctionLoad to load a function that populates this buffer:

https://wolfram.com/xid/0rs5u6a3a-ngv0o5

Call the function by passing the buffer and its length:

https://wolfram.com/xid/0rs5u6a3a-2in6km
Import the raw memory as a list with RawMemoryImport:

https://wolfram.com/xid/0rs5u6a3a-0o98hw

Possible Issues (1)Common pitfalls and unexpected behavior
RawPointer returns a Failure for invalid memory addresses:

https://wolfram.com/xid/0rs5u6a3a-swz10k


Wolfram Research (2023), RawPointer, Wolfram Language function, https://reference.wolfram.com/language/ref/RawPointer.html.
Text
Wolfram Research (2023), RawPointer, Wolfram Language function, https://reference.wolfram.com/language/ref/RawPointer.html.
Wolfram Research (2023), RawPointer, Wolfram Language function, https://reference.wolfram.com/language/ref/RawPointer.html.
CMS
Wolfram Language. 2023. "RawPointer." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RawPointer.html.
Wolfram Language. 2023. "RawPointer." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RawPointer.html.
APA
Wolfram Language. (2023). RawPointer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RawPointer.html
Wolfram Language. (2023). RawPointer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RawPointer.html
BibTeX
@misc{reference.wolfram_2025_rawpointer, author="Wolfram Research", title="{RawPointer}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/RawPointer.html}", note=[Accessed: 05-June-2025
]}
BibLaTeX
@online{reference.wolfram_2025_rawpointer, organization={Wolfram Research}, title={RawPointer}, year={2023}, url={https://reference.wolfram.com/language/ref/RawPointer.html}, note=[Accessed: 05-June-2025
]}