Exemplo n.º 1
0
//Allocation
heap_object *gc_alloc(object_metadata *metadata, size_t size) {
    if ( start_of_heap==NULL ) { gc_init(DEFAULT_MAX_HEAP_SIZE); }
    size = align_to_word_boundary(size);
    heap_object *p = gc_raw_alloc(size);

    memset(p, 0, size);
    p->metadata = metadata;
    p->size = (uint32_t)size;
    return p;
}
Exemplo n.º 2
0
/* Allocate an object per the indicated size, which must included heap_object / header info.
 * The object is zeroed out and the header is initialized.
 */
heap_object *gc_alloc(object_metadata *metadata, size_t size) {
	if (heap == NULL ) { gc_init(DEFAULT_MAX_HEAP_SIZE); }
	size = align_to_word_boundary(size);
	heap_object *p = gc_raw_alloc(size);

	if ( p==NULL ) return NULL;

	memset(p, 0, size);         // wipe out object's data space and the header
	p->magic = MAGIC_NUMBER;    // a safety measure; if not magic num, we didn't alloc
	p->metadata = metadata;     // make sure object knows where its metadata is
	p->size = (uint32_t)size;
	return p;
}