---
title: "RawMemoryRead"
language: "en"
type: "Symbol"
summary: "RawMemoryRead[ptr] reads raw memory from the pointer ptr. RawMemoryRead[ptr, offset] reads from an offset pointer."
keywords: 
- ffi
- foreign function interface
- raw memory read
- raw pointer read
- memory read
- pointer read
- dereference
canonical_url: "https://reference.wolfram.com/language/ref/RawMemoryRead.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Foreign Function Interface"
    link: "https://reference.wolfram.com/language/guide/ForeignFunctionInterface.en.md"
  - 
    title: "C/C++ Language Interface"
    link: "https://reference.wolfram.com/language/guide/CLanguageInterface.en.md"
related_functions: 
  - 
    title: "RawMemoryWrite"
    link: "https://reference.wolfram.com/language/ref/RawMemoryWrite.en.md"
  - 
    title: "RawMemoryAllocate"
    link: "https://reference.wolfram.com/language/ref/RawMemoryAllocate.en.md"
  - 
    title: "RawPointer"
    link: "https://reference.wolfram.com/language/ref/RawPointer.en.md"
  - 
    title: "ManagedObject"
    link: "https://reference.wolfram.com/language/ref/ManagedObject.en.md"
  - 
    title: "RawMemoryImport"
    link: "https://reference.wolfram.com/language/ref/RawMemoryImport.en.md"
  - 
    title: "RawMemoryExport"
    link: "https://reference.wolfram.com/language/ref/RawMemoryExport.en.md"
  - 
    title: "ForeignFunction"
    link: "https://reference.wolfram.com/language/ref/ForeignFunction.en.md"
related_tutorials: 
  - 
    title: "Foreign Functions"
    link: "https://reference.wolfram.com/language/tutorial/ForeignFunctions.en.md"
---
[EXPERIMENTAL]

# RawMemoryRead

RawMemoryRead[ptr] reads raw memory from the pointer ptr.

RawMemoryRead[ptr, offset] reads from an offset pointer.

## Details

* Supported values of ``ptr`` include ``RawPointer`` expressions and ``ManagedObject`` expressions whose values are pointers.

## Examples (4)

### Basic Examples (2)

Allocate an object of type [`"CInt"`](https://reference.wolfram.com/language/ref/compiledtype/CInt.en.md) :

```wl
In[1]:= ptr = RawMemoryAllocate["CInt"];
```

Write a value to the raw memory:

```wl
In[2]:= RawMemoryWrite[ptr, -1];
```

Read the value:

```wl
In[3]:= RawMemoryRead[ptr]

Out[3]= -1
```

---

Export a raw memory representation of a string:

```wl
In[1]:=
str = "A sample text";
ptr = RawMemoryExport[str]

Out[1]=
ManagedObject[RawPointer[5648206752, "UnsignedInteger8"], 
 RawPointer[5648206752, "UnsignedInteger8"], RawMemoryFree]
```

Read the contents of the raw memory:

```wl
In[2]:= Table[RawMemoryRead[ptr, i], {i, 0, StringLength["A sample text"] - 1}]

Out[2]= {65, 32, 115, 97, 109, 112, 108, 101, 32, 116, 101, 120, 116}
```

### Scope (1)

``RawMemoryRead`` supports passing a managed pointer as its first argument:

```wl
In[1]:= ptr = RawMemoryExport["A test."]

Out[1]=
ManagedObject[RawPointer[5183078360, "UnsignedInteger8"], 
 RawPointer[5183078360, "UnsignedInteger8"], RawMemoryFree]

In[2]:= RawMemoryRead[ptr]

Out[2]= 65
```

It also supports passing a non-managed pointer:

```wl
In[3]:= rawPtr = UnmanageObject@ptr

Out[3]= RawPointer[5183078360, "UnsignedInteger8"]

In[4]:= RawMemoryRead[rawPtr]

Out[4]= 65
```

### Properties & Relations (1)

Export a ``ByteArray`` as raw memory:

```wl
In[1]:= ptr = RawMemoryExport[ByteArray[{1, 2, 3, 4, 5}]]

Out[1]=
ManagedObject[RawPointer[5183078344, "UnsignedInteger8"], 
 RawPointer[5183078344, "UnsignedInteger8"], RawMemoryFree]
```

``RawMemoryRead`` reads the contents of the raw memory:

```wl
In[2]:= Table[RawMemoryRead[ptr, i], {i, 0, 4}]

Out[2]= {1, 2, 3, 4, 5}
```

``RawMemoryImport`` can be used for the same purpose:

```wl
In[3]:= RawMemoryImport[ptr, {"List", 5}]

Out[3]= {1, 2, 3, 4, 5}
```

## See Also

* [`RawMemoryWrite`](https://reference.wolfram.com/language/ref/RawMemoryWrite.en.md)
* [`RawMemoryAllocate`](https://reference.wolfram.com/language/ref/RawMemoryAllocate.en.md)
* [`RawPointer`](https://reference.wolfram.com/language/ref/RawPointer.en.md)
* [`ManagedObject`](https://reference.wolfram.com/language/ref/ManagedObject.en.md)
* [`RawMemoryImport`](https://reference.wolfram.com/language/ref/RawMemoryImport.en.md)
* [`RawMemoryExport`](https://reference.wolfram.com/language/ref/RawMemoryExport.en.md)
* [`ForeignFunction`](https://reference.wolfram.com/language/ref/ForeignFunction.en.md)

## Tech Notes

* [Foreign Functions](https://reference.wolfram.com/language/tutorial/ForeignFunctions.en.md)

## Related Guides

* [Foreign Function Interface](https://reference.wolfram.com/language/guide/ForeignFunctionInterface.en.md)
* [C/C++ Language Interface](https://reference.wolfram.com/language/guide/CLanguageInterface.en.md)

## History

* [Introduced in 2023 (13.3)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn133.en.md)