Introduction

While ForthOS also offers the traditional Forth heap
memory allocator ("allot", ",", "here", "forget"), there are many
applications where it is easier if memory objects are allocated
and freed in an arbitrary order. The ForthOS bucket
memory allocator is available for these purposes. Both
methods of allocation can coexist; the Forth heap grows from lower
memory upward, and the bucket allocator takes memory from the top
of memory downward.

The Words

bkalloc ( u -- a )

Allocates "u" bytes of memory, and returns a pointer to this storage.

bkzalloc ( u -- a )

Like bkalloc, but the memory is zeroed.

bkfree ( a -- )

Frees previously allocated memory.

bkrealloc ( a u -- a' )

Changes the allocation size of a previously allocated chunk of
memory. Returns a (possibly changed) pointer to the contents.
The contents through the lesser of the old and new sizes is preserved.
After this call, only the returned pointer value should be used
to access the memory.

Other Considerations

Unlike the Forth heap memory, bucket memory is not preserved across
an "unexec" operation.

The memory is organized in "buckets" which increase by powers of two.
Thus, the actual memory consumed can be quite a bit larger than the
size you actually requested. This scheme is used because it is much
more resistant to memory fragmentation than "best fit" type allocators.