cuoo/halloc.h: Hash-Consing Allocation
[cuoo: Dynamic Objects and Operations]

Defines

#define CUOO_HCOBJ_KEY_SIZEW(struct_size)   (((struct_size) + CU_WORD_SIZE - 1 - CUOO_HCOBJ_SHIFT)/CU_WORD_SIZE)
#define CUOO_HCOBJ_KEY_SIZE(struct_size)   (CUOO_HCOBJ_KEY_SIZEW(struct_size)*CU_WORD_SIZE)
#define CUOO_HCOBJ_ALLOC_SIZEG(struct_size)   CUOO_OBJ_ALLOC_SIZEG(struct_size)
#define cuoo_hxnew_init(prefix, key_size, key, init_nonkey)
#define cuoo_hxnew_setao(prefix, key_size, key, ao_offset, ao_value)
#define cuoo_hxnew_clear(prefix, key_size, key)

Functions

void * cuoo_halloc (cuoo_type_t type, size_t key_size, void *key)
void * cuoo_hxalloc_init (cuoo_type_t type, size_t struct_size, size_t key_size, void *key, cu_clop(init_nonkey, void, void *obj))
void * cuoo_hxalloc_setao (cuoo_type_t type, size_t struct_size, size_t key_size, void *key, cu_offset_t ao_offset, AO_t ao_value)
void * cuoo_hxalloc_clear (cuoo_type_t type, size_t struct_size, size_t key_size, void *key)

Detailed Description

This is the generic API for hash-consing. The macros in cuoo/hctem.h may be more convinent.


Define Documentation

#define cuoo_hxnew_clear ( prefix,
key_size,
key   ) 
Value:
((struct prefix *) \
     cuoo_hxalloc_clear(prefix##_type(), sizeof(struct prefix), \
                        key_size, key))

Macro to call cuoo_hxalloc_clear based on an indentifier prefix. See cuoo_hxnew_init for details.

#define cuoo_hxnew_init ( prefix,
key_size,
key,
init_nonkey   ) 
Value:
((struct prefix *) \
     cuoo_hxalloc_init(prefix##_type(), sizeof(struct prefix), \
                       key_size, key, init_nonkey))

A macro which construct a call to cuoo_hxalloc_init given a prefix to identifier names related to the type. In particular, the following must be defined:

  • struct prefix { CU_HCOBJ ... } — The struct of the object, used for size calculation and the return type.
  • cuoo_type_t prefix_type(void) — A function or function-like macro which shall return the dynamic type of the object.
#define cuoo_hxnew_setao ( prefix,
key_size,
key,
ao_offset,
ao_value   ) 
Value:
((struct prefix *) \
     cuoo_hxalloc_setao(prefix##_type(), sizeof(struct prefix), \
                        key_size, key, ao_offset, ao_value))

Macro to call cuoo_hxalloc_setao based on an indentifier prefix. See cuoo_hxnew_init for details.


Function Documentation

void* cuoo_halloc ( cuoo_type_t  type,
size_t  key_size,
void *  key 
)

General hash-consing allocation, allowing more control than cuoo_hctem_new.

void* cuoo_hxalloc_clear ( cuoo_type_t  type,
size_t  struct_size,
size_t  key_size,
void *  key 
)

As cuoo_hxalloc_init specialised with initialisation that only clear the non-key data.

void* cuoo_hxalloc_init ( cuoo_type_t  type,
size_t  struct_size,
size_t  key_size,
void *  key,
cu_clop(init_nonkey, void, void *obj)   
)

General hash-consing allocation with extra non-keyed memory. This generally takes more GC cycles to clean up and is therefore more expensive than cuoo_halloc, but it allows caching computations and associating properties to live objects.

void* cuoo_hxalloc_setao ( cuoo_type_t  type,
size_t  struct_size,
size_t  key_size,
void *  key,
cu_offset_t  ao_offset,
AO_t  ao_value 
)

As cuoo_hxalloc_init specialised with initialisation that simply sets an AO_t typed field at offset oa_offset to ao_value.

Generated 2009-11-23 for culibs-0.25 using Doxygen. Maintained by Petter Urkedal.