Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

Memory Management
[Simple Objects C API]


Detailed Description

Functions and macros dealing with memory managenent.

Most of the memory managenent is based on garbage collection using reference counting. New objects have an initial reference count of zero. A reference counter of zero is valid an indicates that an object is referenced only by local variables. References from local variables may or may not be counted in the reference counter, depending on the situation.


Defines

#define SOBJ_REFCOUNT_T_FMT   "%lu"
 printf() style format string for converting a reference counter to decimal representation.
#define SOBJ_REFCOUNT_MASK   ((sobj_refcount_t)~0L >> 2)
 The reference counter mask.
#define SOBJ_RETAIN(OBJECT)   (sobj_retain((OBJECT)))
 Retain a reference counted object.
#define SOBJ_RELEASE(OBJECT)   (sobj_release((OBJECT)))
 Release a reference counted object.
#define SOBJ_DROP(OBJECT)   (sobj_drop((OBJECT)))
 Discard an unreferenced reference counted object.
#define SOBJ_UNRETAIN(OBJECT)   (sobj_unretain((OBJECT)))
 Release a reference counted object without discarding unreferenced objects.
#define SOBJ_XRETAIN(OBJECT)   (sobj_xretain((OBJECT)))
 Retain a reference counted object.
#define SOBJ_XRELEASE(OBJECT)   (sobj_xrelease((OBJECT)))
 Release a reference counted object.
#define SOBJ_XDROP(OBJECT)   (sobj_xdrop((OBJECT)))
 Discard an unreferenced reference counted object.
#define SOBJ_XUNRETAIN(OBJECT)   (sobj_xunretain((OBJECT)))
 Release a reference counted object without discarding unreferenced objects.

Typedefs

typedef unsigned long sobj_refcount_t
 Integer type used for reference counters.

Functions

void * sobj_malloc (size_t size)
 Heap allocation function.
void * sobj_realloc (void *mem, size_t size)
 Heap re-allocation function.
void sobj_free (void *mem)
 Heap free function.
char * sobj_strdup (const char *string)
 Duplicate a null-terminated string.
void * sobj_retain (void *object)
 Increase the referece count of an object (retain the object).
void sobj_release (void *object)
 Decrease the referece count of an object and delete ob zero (release the object).
void sobj_unretain (void *object)
 Decrease the referece count of an object without deletion on zero (unretain the object).
void sobj_drop (void *object)
 Delete an object if the referece counter is zero.
sobj_refcount_t sobj_refcount (void *object)
 Get the current referece counted of the specified object.
void * sobj_xretain (void *object)
 Increase the referece count of an object (retain the object).
void sobj_xrelease (void *object)
 Decrease the referece count of an object and delete ob zero (release the object).
void sobj_xunretain (void *object)
 Decrease the referece count of an object without deletion on zero (unretain the object).
void sobj_xdrop (void *object)
 Delete an object if the referece counter is zero.


Define Documentation

#define SOBJ_DROP OBJECT   )     (sobj_drop((OBJECT)))
 

Discard an unreferenced reference counted object.

This macro tests if the reference counter of a reference counted object is zero. If the reference counter is 0, the destructor function of the object is called.

Parameters:
OBJECT The reference counted object.

#define SOBJ_REFCOUNT_MASK   ((sobj_refcount_t)~0L >> 2)
 

The reference counter mask.

#define SOBJ_REFCOUNT_T_FMT   "%lu"
 

printf() style format string for converting a reference counter to decimal representation.

#define SOBJ_RELEASE OBJECT   )     (sobj_release((OBJECT)))
 

Release a reference counted object.

This macro decreases the reference counter of a reference counted object. If the reference counter is decreased to 0, the destructor function of the object is called.

Parameters:
OBJECT The reference counted object.

#define SOBJ_RETAIN OBJECT   )     (sobj_retain((OBJECT)))
 

Retain a reference counted object.

This macro increases the reference counter of a reference counted object.

Parameters:
OBJECT The reference counted object.

#define SOBJ_UNRETAIN OBJECT   )     (sobj_unretain((OBJECT)))
 

Release a reference counted object without discarding unreferenced objects.

This macro decreases the reference counter of a reference counted object. The destructor function of the object is not called, even if the reference counter is decreased to 0.

Parameters:
OBJECT The reference counted object.

#define SOBJ_XDROP OBJECT   )     (sobj_xdrop((OBJECT)))
 

Discard an unreferenced reference counted object.

This macro tests if the reference counter of a reference counted object is zero. If the reference counter is 0, the destructor function of the object is called.

Parameters:
OBJECT The reference counted object. This may be a null-pointer.

#define SOBJ_XRELEASE OBJECT   )     (sobj_xrelease((OBJECT)))
 

Release a reference counted object.

This macro decreases the reference counter of a reference counted object. If the reference counter is decreased to 0, the destructor function of the object is called.

Parameters:
OBJECT The reference counted object. This may be a null-pointer.

#define SOBJ_XRETAIN OBJECT   )     (sobj_xretain((OBJECT)))
 

Retain a reference counted object.

This macro increases the reference counter of a reference counted object.

Parameters:
OBJECT The reference counted object. This may be a null-pointer.

#define SOBJ_XUNRETAIN OBJECT   )     (sobj_xunretain((OBJECT)))
 

Release a reference counted object without discarding unreferenced objects.

This macro decreases the reference counter of a reference counted object. The destructor function of the object is not called, even if the reference counter is decreased to 0.

Parameters:
OBJECT The reference counted object. This may be a null-pointer.


Typedef Documentation

typedef unsigned long sobj_refcount_t
 

Integer type used for reference counters.


Function Documentation

void sobj_drop void *  object  ) 
 

Delete an object if the referece counter is zero.

The macro does nothing if the referece counter of the specified object is non-zero.

Parameters:
object A referece counted object.

void sobj_free void *  mem  ) 
 

Heap free function.

Parameters:
mem Pointer to the heap block to be freed.

void* sobj_malloc size_t  size  ) 
 

Heap allocation function.

Parameters:
size The number of bytes to be allocated.
Returns:
A pointer to a heap-allocated buffer of the requested size. The function never returns a null-pointer.

void* sobj_realloc void *  mem,
size_t  size
 

Heap re-allocation function.

Parameters:
mem Pointer to the heap block to be re-allocated.
size The new size of the block.
Returns:
A pointer to a heap-allocated buffer of the requested size. If the memory block has to be moved then the contents of the block will be copied to the new buffer. The function never returns a null-pointer.

sobj_refcount_t sobj_refcount void *  object  ) 
 

Get the current referece counted of the specified object.

Parameters:
object A referece counted object.
Returns:
The (plain) referece counter of the specified object.

void sobj_release void *  object  ) 
 

Decrease the referece count of an object and delete ob zero (release the object).

This macro will call the destructor callback function of the specified object if the referece counter is decreased to zero.

Parameters:
object A referece counted object.

void* sobj_retain void *  object  ) 
 

Increase the referece count of an object (retain the object).

Parameters:
object A referece counted object.
Returns:
The object.

char* sobj_strdup const char *  string  ) 
 

Duplicate a null-terminated string.

Parameters:
string The string.
Returns:
A heap allocated copy of the specified string.

void sobj_unretain void *  object  ) 
 

Decrease the referece count of an object without deletion on zero (unretain the object).

This macro will not delete the specified object if the referece counted is decreased to zero.

Parameters:
object A referece counted object.

void sobj_xdrop void *  object  ) 
 

Delete an object if the referece counter is zero.

The macro does nothing if the referece counter of the specified object is non-zero.

Parameters:
object A referece counted object. This may be a null-pointer.

void sobj_xrelease void *  object  ) 
 

Decrease the referece count of an object and delete ob zero (release the object).

This macro will call the destructor callback function of the specified object if the referece counter is decreased to zero.

Parameters:
object A referece counted object. This may be a null-pointer.

void* sobj_xretain void *  object  ) 
 

Increase the referece count of an object (retain the object).

Parameters:
object A referece counted object. This may be a null-pointer.
Returns:
The object.

void sobj_xunretain void *  object  ) 
 

Decrease the referece count of an object without deletion on zero (unretain the object).

This macro will not delete the specified object if the referece counted is decreased to zero.

Parameters:
object A referece counted object. This may be a null-pointer.


Generated on Sat Jul 23 16:07:33 2005 for sobject by  doxygen 1.3.9.1