Assemblyscript: Query from JavaScript which memory allocator is used

Created on 23 Feb 2019  路  2Comments  路  Source: AssemblyScript/assemblyscript

Hi, each allocator has its own strengths and depending on the use case I wanna run some other code in JavaScript. Is there any way to query in JavaScript if e.g. TLSF or Arena is used?

question stale

Most helpful comment

You'll need to inspect the wasm binary. This is from an arena binary's text file.

(global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0))
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))

You could export which one of these, but exporting mutable globals requires a flag and isn't supported on all platforms. So unless you can just export yourself which type you'll have to examine the bits.

I've been working on lib/parser to make it easier, though for now I'd recommend using binaryen.js. My hope for the assemblyscript parser is to help do tasks like merging two binaries at runtime. This way you could switch out which memory allocator without having to recompile and more generally allow for easier dynamic linking and loading, particularly with other non-AS binaries.

All 2 comments

You'll need to inspect the wasm binary. This is from an arena binary's text file.

(global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0))
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))

You could export which one of these, but exporting mutable globals requires a flag and isn't supported on all platforms. So unless you can just export yourself which type you'll have to examine the bits.

I've been working on lib/parser to make it easier, though for now I'd recommend using binaryen.js. My hope for the assemblyscript parser is to help do tasks like merging two binaries at runtime. This way you could switch out which memory allocator without having to recompile and more generally allow for easier dynamic linking and loading, particularly with other non-AS binaries.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kungfooman picture kungfooman  路  5Comments

torch2424 picture torch2424  路  3Comments

andy-hanson picture andy-hanson  路  4Comments

MaxGraey picture MaxGraey  路  4Comments

lastmjs picture lastmjs  路  4Comments