Skip to content

Commit

Permalink
docs: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaewoook committed Jan 20, 2024
1 parent 4eccd15 commit 411db49
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,27 @@ PDFium().then((PDFiumModule) => {
});
```

### Memory Management
### WASM Memory Management

Here is simple code snippets about memory management.

The WASM Memory can be found in `PDFiumModule.FPDF.HEAP*` properties.

```ts
import { PDFium } from "pdfium.js";
import { PDFium, memory } from "pdfium.js";

// options parameter can be skipped after the module loaded
PDFium().then((PDFiumModule) => {
const bytes = 1024;
const nBytes = 1024;

// allocate 1024 bytes in wasm memory
const memoryAddress = PDFiumModule.wasmExports.malloc(nBytes);

// you can also use calloc() to allocate 1024 bytes (array of 256 integers)
const memoryAddress2 = memory.calloc(256, 4);

// allocate 1024 bytes in memory
const memoryAddress = PDFiumModule.wasmExports.malloc(bytes);
// zero-fill allocated memory
memory.fill(PDFiumModule.FPDF.HEAPU8, memoryAddress, nBytes);

// free memory
PDFiumModule.wasmExports.free(memoryAddress);
Expand Down

0 comments on commit 411db49

Please sign in to comment.