RawPointer
RawPointer[addr,type]
represents a raw pointer to the specified type at the memory address addr.
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)
Export a string as raw memory represented by a managed RawPointer:
Write a value to the raw memory:
Scope (1)
Information (1)
Create a pointer to raw memory:
Get Information about the pointer:
Properties & Relations (5)
Functions like RawMemoryAllocate return a memory-managed RawPointer:
Call UnmanageObject to take ownership of the managed pointer:
Notice that the memory management of the pointer allocated is no longer active:
Unmanaged pointers should be freed with RawMemoryFree to avoid memory leaks:
NullRawPointerQ returns True if a raw pointer has 0 as its address:
Convert a RawPointer into an OpaqueRawPointer:
Convert the opaque raw pointer back to a RawPointer:
Allocate a raw memory for an object of type "UnsignedInteger8":
Write a value to the raw memory by passing the pointer to RawMemoryWrite:
Read the raw memory with RawMemoryRead:
Allocate a buffer of 10 "CLong" objects:
Use ForeignFunctionLoad to load a function that populates this buffer:
Call the function by passing the buffer and its length:
Import the raw memory as a list with RawMemoryImport:
Possible Issues (1)
RawPointer returns a Failure for invalid memory addresses:
Text
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.
APA
Wolfram Language. (2023). RawPointer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RawPointer.html