Main Page | Modules | Data Structures | Data Fields

Allocation


Detailed Description

Peak's allocation mechanism uses the standard malloc/free pair but can be configured as wish with peak_alloc_configure() providing your own allocation and deallocation primitives.
Although written in C, peak is object oriented and features a lightweight support for reference counting in all peak objects. This module offers access to the peak_retain() an peak_release() method.
Strings, however, are normal C strings and not wrapped by the peak library. For convenience, a peak_strdup() method is provided as well.


Typedefs

typedef void *(* peak_alloc_malloc_func )(size_t size)
 Malloc-like function pointer type.

typedef void(* peak_alloc_free_func )(void *p)
 Free-like function pointer type.


Functions

void peak_alloc_configure (peak_alloc_malloc_func malloc_fun, peak_alloc_free_func free_fun)
 Configure peak's allocation for your program.

void * peak_allocate (size_t size)
 Allocate memory.

void peak_deallocate (void *ptr)
 Free memory.

char * peak_strdup (const char *str)
 Copy a string.

void * peak_retain (void *obj)
 Retain a peak object.

void peak_release (void *obj)
 Release a peak object.

int peak_get_retcnt (void *obj)
 Get the retain count of a peak object.


Function Documentation

void peak_alloc_configure peak_alloc_malloc_func  malloc_fun,
peak_alloc_free_func  free_fun
 

Configure peak's allocation for your program.

Pointed functions must properly align memory and be thread-safe like malloc() and free()...

Parameters:
malloc_fun A pointer to your custom malloc-like function.
free_fun A pointer to your custom free-like function.

void* peak_allocate size_t  size  ) 
 

Allocate memory.

Parameters:
size Number of bytes of memory to allocate.
Returns:
A pointer to the fresh allocated memory.

void peak_deallocate void *  ptr  ) 
 

Free memory.

Parameters:
ptr Pointer to the memory space to deallocate.

int peak_get_retcnt void *  obj  ) 
 

Get the retain count of a peak object.

Parameters:
obj Any peak object.
Returns:
Retain count or -1 for constant objects.

void peak_release void *  obj  ) 
 

Release a peak object.

Decrease the reference count of the object obj. If the refcount is 0, the object is deallocated.

Parameters:
obj Any peak object.

void* peak_retain void *  obj  ) 
 

Retain a peak object.

Increase the reference count of the object obj.

Parameters:
obj Any peak object.
Returns:
For convenience, a pointer to obj.

char* peak_strdup const char *  str  ) 
 

Copy a string.

Parameters:
str The string to copy/duplicate.
Returns:
A pointer to a new allocated copy of the string. It should be passed to peak_deallocate() if you want to free it.


Generated on Thu Jan 8 18:16:23 2004 for the PEAK Library by doxygen     SourceForge.net Logo