# heap
直接使用动态内存管理器的不安全接口,类似于 malloc
、realloc
和 free
。手动内存管理可以与垃圾收集并行使用,这非常方便,但是手动管理的块不能与垃圾收集的对象混合(即尝试分别对 GC 对象进行 heap.free
或将块强制转换为托管对象会中断,因为 有 GC 标头,而另一个则没有)。
¥An unsafe interface to use the dynamic memory manager directly, resembling malloc
, realloc
and free
. Manual memory management can be used in parallel to garbage collection, which can be quite handy, but manually managed blocks cannot be mixed with garbage collected objects (i.e. trying to heap.free
a GC object or casting a block to a managed object respectively would break since one has a GC header and the other does not).
# 静态成员
¥Static members
function heap.alloc(size: usize): usize
分配至少指定大小的内存块。
¥Allocates a chunk of memory of at least the specified size.
function heap.realloc(ptr: usize, size: usize): usize
重新分配一块内存,使其至少具有指定的大小。
¥Reallocates a chunk of memory to have at least the specified size.
function heap.free(ptr: usize): void
释放一块内存。
¥Frees a chunk of memory.
function heap.reset(): void
危险地重置整个堆。特定于 "stub" 运行时。
¥Dangerously resets the entire heap. Specific to the "stub" runtime.