Skip to content

Commit 2e5b7da

Browse files
committed
docs: add explanation about pointer caching
1 parent 03505ab commit 2e5b7da

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

docs/basics/pointers.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,30 @@ p_raw = ptr(MemoryResolver(memory, 0)) # no wrapper
138138
p2 = p_raw + 4 # advances by 4 bytes
139139
```
140140

141+
## Caching
142+
143+
Pointer dereferencing is cached — repeated calls to `unwrap()` or `try_unwrap()` return the same object without re-inflating:
144+
145+
```python
146+
r1 = node.next.unwrap()
147+
r2 = node.next.unwrap()
148+
assert r1 is r2 # same object
149+
```
150+
151+
If the underlying memory changes, call `invalidate()` to clear the cache:
152+
153+
```python
154+
# Memory was modified externally
155+
node.next.invalidate()
156+
r3 = node.next.unwrap() # re-inflated from updated memory
157+
```
158+
159+
Setting the pointer's value automatically invalidates the cache:
160+
161+
```python
162+
node.next.value = new_address # cache cleared automatically
163+
```
164+
141165
## Pointer String Representation
142166

143167
```python

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ nav:
6565
- Freeze, Diff & Reset: advanced/freeze_diff.md
6666
- C Struct Parser: advanced/c_parser.md
6767
- Forward References: advanced/forward_refs.md
68+
- Hex Dump: advanced/hexdump.md
6869
- Field Offsets: advanced/offset.md

0 commit comments

Comments
 (0)