NAME ^

src/resources.c - Allocate and deallocate tracked resources

DESCRIPTION ^

Parrot Memory Management Code ^

static void *alloc_new_block(Interp *interpreter, size_t size, struct Memory_Pool *pool)

Allocate a new memory block. We allocate the larger of however much was asked for or the default size, whichever's larger.

static void *mem_allocate(Interp *interpreter, size_t *req_size, struct Memory_Pool *pool, size_t align_1)

Allocates memory for headers.

Alignment problems: align_1 sets the size, but not the alignment of the memory block we are about to allocate. The alignment of this block is currently determined by the align_1 sent in by the previous allocation. See http://archive.develooper.com/perl6-internals%40perl.org/msg12310.html for details. Currently, we work around it by forcing all the *ALIGNMENT #defines in <include/parrot/file.h> to be the same.

Compaction Code ^

static void compact_pool(Interp *interpreter, struct Memory_Pool *pool)

Compact the buffer pool.

void Parrot_go_collect(Interp *interpreter)

Go do a GC run. This only scans the string pools and compacts them, it doesn't check for string liveness.

Parrot Re/Allocate Code ^

void *Parrot_reallocate(Interp *interpreter, void *from, size_t tosize)

Takes an interpreter, a buffer pointer, and a new size. The buffer pointer is in as a void * because we may take a STRING or something, and C doesn't subclass.

void *Parrot_reallocate_string(Interp *interpreter, STRING *str, size_t tosize)

Takes an interpreter, a STRING pointer, and a new size. The destination may be bigger, since we round up to the allocation quantum.

void *Parrot_allocate(Interp *interpreter, void *buffer, size_t size)

Allocate exactly as much memory as they asked for.

void *Parrot_allocate_zeroed(Interp *interpreter, void *buffer, size_t size)

Just calls Parrot_allocate(), which also returns zeroed memory.

void *Parrot_allocate_string(Interp *interpreter, STRING *str, size_t size)

Allocate at least as much memory as they asked for. We round the amount up to the allocation quantum.

static struct Memory_Pool *new_memory_pool(size_t min_block, compact_f compact)

Create a new memory pool.

void Parrot_initialize_memory_pools(Interp *interpreter)

Initialize the managed memory pools.

void Parrot_destroy_memory_pools(Interp *interpreter)

Destroys the memory pools.

SEE ALSO ^

include/parrot/resources.h, src/memory.c.

HISTORY ^

Initial version by Dan on 2001.10.2.


parrot