Skip to content

Commit c16c9f0

Browse files
committed
docs: add memory management section to README
1 parent 386d2f2 commit c16c9f0

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,36 @@ createBufferReader(buffer: ArrayBuffer, schema: readonly ColumnType[])
187187

188188
---
189189

190+
## 🗂 Memory management
191+
192+
**Buffer ownership**
193+
194+
`ColumnarWriterBuilder` allocates a `std::vector<uint8_t>` internally. Calling `toArrayBuffer(rt)` moves the vector into a `shared_ptr<VectorBuffer>` (a `jsi::MutableBuffer` subclass) and hands it to the JSI runtime — the builder is empty after this call and must not be used again.
195+
196+
**Lifetime on the JS side**
197+
198+
The JS runtime (Hermes / V8) becomes the sole owner of the `ArrayBuffer`. All typed-array views returned by `createBufferReader` are zero-copy views over the same memory — each view holds an implicit reference to the `ArrayBuffer`.
199+
200+
The underlying `std::vector` is freed when **all** JS references are gone: the original `ArrayBuffer` object and every typed-array view derived from it. No explicit `free()` or reference counting is required.
201+
202+
```
203+
ColumnarWriterBuilder → toArrayBuffer() → shared_ptr<VectorBuffer>
204+
205+
jsi::ArrayBuffer ───────┘ (JSI runtime owns)
206+
207+
Int32Array / Float64Array / … (views, no copy)
208+
209+
All JS refs dropped → GC → shared_ptr ref-count = 0 → vector freed
210+
```
211+
212+
**Practical rules**
213+
214+
- Don't keep a typed-array view alive longer than needed — it pins the entire buffer in memory.
215+
- Don't call `toArrayBuffer()` more than once on the same builder.
216+
- Buffer size is fixed at construction time (`rows` passed to the builder constructor).
217+
218+
---
219+
190220
## ⚠️ Limitations
191221

192222
Designed for dense numeric data only. Strings, nullable values, nested objects, and variable-length fields are not supported natively — encode them as fixed-width columns using ids, offsets, or sentinel values.

0 commit comments

Comments
 (0)