mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-16 16:31:32 +00:00
Portable not-so-smart Heap
This commit is contained in:
@ -9,9 +9,13 @@ let HEAP_OFFSET: usize = HEAP_START; // HEAP_START is a constant generated by th
|
||||
class Heap {
|
||||
|
||||
static allocate(size: usize): usize {
|
||||
if (!size) return 0;
|
||||
const len: i32 = current_memory();
|
||||
if (HEAP_OFFSET + size > <usize>len << 16)
|
||||
if(grow_memory(max<i32>(<i32>ceil<f64>(<f64>size / 65536), len * 2 - len)) < 0)
|
||||
unreachable();
|
||||
const ptr: usize = HEAP_OFFSET;
|
||||
assert(ptr + size <= (<usize>current_memory() << 16));
|
||||
if (((HEAP_OFFSET += size) & ALIGN_MASK) != 0) // align next offset
|
||||
if ((HEAP_OFFSET += size) & ALIGN_MASK) // align next offset
|
||||
HEAP_OFFSET = (HEAP_OFFSET | ALIGN_MASK) + 1;
|
||||
return ptr;
|
||||
}
|
||||
|
Reference in New Issue
Block a user