aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-09 19:49:38 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-09 19:49:38 -0700
commit85d80d8fb7e6f32979b82bdf26c93c30bfea578a (patch)
tree486f1fb5b395c0096ba2575b986b39018e3ea47a
parent695da9ee291c67f2e6caa547b3ef2720dde6cb6b (diff)
downloadbun-85d80d8fb7e6f32979b82bdf26c93c30bfea578a.tar.gz
bun-85d80d8fb7e6f32979b82bdf26c93c30bfea578a.tar.zst
bun-85d80d8fb7e6f32979b82bdf26c93c30bfea578a.zip
Update README.md
-rw-r--r--README.md23
1 files changed, 19 insertions, 4 deletions
diff --git a/README.md b/README.md
index 0c4400674..5957d8539 100644
--- a/README.md
+++ b/README.md
@@ -3000,7 +3000,7 @@ const myPtr = ptr(myTypedArray);
myTypedArray = new Uint8Array(toArrayBuffer(myPtr, 0, 32), 0, 32);
```
-**To read data from a pointer**:
+**To read data from a pointer**
You have two options.
@@ -3018,14 +3018,15 @@ console.log(
);
```
-_Available in Bun v0.1.12+_
-
For short-lived pointers, `read` is the fastest option:
+_Available in Bun v0.1.12+_
+
```ts
import { read } from "bun:ffi";
console.log(
+ // ptr, byteOffset
read.u8(myPtr, 0),
read.u8(myPtr, 1),
read.u8(myPtr, 2),
@@ -3033,7 +3034,21 @@ console.log(
);
```
-Read behaves similarly to `DataView`, but it can be faster because it doesn't need to create a `DataView` or `ArrayBuffer`.
+`read` behaves similarly to `DataView`, but it can be faster because it doesn't need to create a `DataView` or `ArrayBuffer`.
+
+| `FFIType` | `read` function |
+| --------- | --------------- |
+| ptr | `read.ptr` |
+| i8 | `read.i8` |
+| i16 | `read.i16` |
+| i32 | `read.i32` |
+| i64 | `read.i64` |
+| u8 | `read.u8` |
+| u16 | `read.u16` |
+| u32 | `read.u32` |
+| u64 | `read.u64` |
+| f32 | `read.f32` |
+| f64 | `read.f64` |
**Memory management with pointers**: