mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-05-02 02:12:15 +00:00
more
This commit is contained in:
parent
18c3f0c555
commit
2b0a165e7f
@ -12,6 +12,9 @@ Interface
|
||||
Dynamically allocates a chunk of memory of at least the specified size and returns its address.
|
||||
Alignment is guaranteed to be 16 bytes to fit up to v128 values naturally.
|
||||
|
||||
* **__rt_reallocate**(ref: `usize`, size: `usize`): `usize`<br />
|
||||
Dynamically changes the size of a chunk of memory, possibly moving it to a new address.
|
||||
|
||||
* **__rt_free**(ref: `usize`): `void`<br />
|
||||
Frees a dynamically allocated chunk of memory by its address.
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { AL_MASK, CommonBlock } from "./common";
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@inline
|
||||
const BLOCK_OVERHEAD = offsetof<CommonBlock>();
|
||||
const BLOCK_OVERHEAD = (offsetof<CommonBlock>() + AL_MASK) & ~AL_MASK;
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@inline
|
||||
@ -43,9 +43,15 @@ function __rt_allocate(size: usize, id: u32): usize {
|
||||
@unsafe @global
|
||||
function __rt_reallocate(ref: usize, size: usize): usize {
|
||||
var block = changetype<CommonBlock>(ref - BLOCK_OVERHEAD);
|
||||
var newRef = __rt_allocate(size, block.rtId);
|
||||
memory.copy(newRef, ref, block.rtSize);
|
||||
return newRef;
|
||||
var oldSize = <usize>block.rtSize;
|
||||
if (size > oldSize) {
|
||||
let newRef = __rt_allocate(size, block.rtId);
|
||||
memory.copy(newRef, ref, oldSize);
|
||||
ref = newRef;
|
||||
} else {
|
||||
block.rtSize = size;
|
||||
}
|
||||
return ref;
|
||||
}
|
||||
|
||||
// @ts-ignore: decorator
|
||||
|
Loading…
x
Reference in New Issue
Block a user