diff options
Diffstat (limited to 'src/preamble.js')
-rw-r--r-- | src/preamble.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/preamble.js b/src/preamble.js index 14bf4d36..9342bf2b 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -472,9 +472,11 @@ Module['getValue'] = getValue; var ALLOC_NORMAL = 0; // Tries to use _malloc() var ALLOC_STACK = 1; // Lives for the duration of the current function call var ALLOC_STATIC = 2; // Cannot be freed +var ALLOC_NONE = 3; // Do not allocate Module['ALLOC_NORMAL'] = ALLOC_NORMAL; Module['ALLOC_STACK'] = ALLOC_STACK; Module['ALLOC_STATIC'] = ALLOC_STATIC; +Module['ALLOC_NONE'] = ALLOC_NONE; // allocate(): This is for internal use. You can use it yourself as well, but the interface // is a little tricky (see docs right below). The reason is that it is optimized @@ -489,7 +491,7 @@ Module['ALLOC_STATIC'] = ALLOC_STATIC; // is initial data - if @slab is a number, then this does not matter at all and is // ignored. // @allocator: How to allocate memory, see ALLOC_* -function allocate(slab, types, allocator) { +function allocate(slab, types, allocator, ptr) { var zeroinit, size; if (typeof slab === 'number') { zeroinit = true; @@ -501,7 +503,12 @@ function allocate(slab, types, allocator) { var singleType = typeof types === 'string' ? types : null; - var ret = [_malloc, Runtime.stackAlloc, Runtime.staticAlloc][allocator === undefined ? ALLOC_STATIC : allocator](Math.max(size, singleType ? 1 : types.length)); + var ret; + if (allocator == ALLOC_NONE) { + ret = ptr; + } else { + ret = [_malloc, Runtime.stackAlloc, Runtime.staticAlloc][allocator === undefined ? ALLOC_STATIC : allocator](Math.max(size, singleType ? 1 : types.length)); + } if (zeroinit) { _memset(ret, 0, size); |