OpenGL Volumizer 2.7 Reference Pages


NAME
vzMemory - Memory allocation and de-allocation routines.

HEADER FILE
#include <Volumizer2/Memory.h>

PUBLIC METHOD SUMMARY
static void operator delete ( void* ptr);
static void* operator new ( size_t nbytes);
static void setMemoryManagementCallbacks ( vzMemoryAllocationCallback allocateCB, vzMemoryDeletionCallback deleteCB, void* userData);
static void getMemoryManagementCallbacks ( vzMemoryAllocationCallback& allocateCB, vzMemoryDeletionCallback& deleteCB, void*& userData);
static void* malloc ( size_t nbytes);
static void free ( void* ptr);

PROTECTED METHOD SUMMARY
vzMemory (  );
virtual ~vzMemory (  );

CLASS DESCRIPTION
This class provides arbitrary user-defined memory management functionality. vzMemory is the base class for all object classes in Volumizer. By installing memory allocation and deletion callbacks, the user can override the default operators new() and delete(). This could be useful in allocating objects in shared memory, for example.

METHOD DESCRIPTIONS

   vzMemory()
vzMemory (  );

Constructor.

   ~vzMemory()
virtual ~vzMemory (  );

Destructor.

   free()
static void free ( void* ptr);

Deallocates the data pointer ptr using the memory deletion callback.

   getMemoryManagementCallbacks()
static void getMemoryManagementCallbacks ( vzMemoryAllocationCallback& allocateCB, vzMemoryDeletionCallback& deleteCB, void*& userData);

Use this method to get the user-defined memory management functions.

   malloc()
static void* malloc ( size_t nbytes);

Allocates nbytes of memory using the memory allocation callback and returns pointer to the allocated memory.

   operator delete()
static void operator delete ( void* ptr);

Memory deletion operator for object classes in Volumizer. The behavior of the operator is dependent upon the deletion callback specified by setMemoryManagementCallbacks(). The default behavior is to call the free() function.

   operator new()
static void* operator new ( size_t nbytes);

Memory allocation operator for object classes in Volumizer. The behavior of the operator is dependent upon the allocation callback specified by setMemoryManagementCallbacks(). The default behavior is to call the malloc() function.

   setMemoryManagementCallbacks()
static void setMemoryManagementCallbacks ( vzMemoryAllocationCallback allocateCB, vzMemoryDeletionCallback deleteCB, void* userData);

Use this method to specify arbitrary user-defined memory management functions. The parameters specify a memory allocation callback, a memory deletion callback, and a user data pointer. The callbacks are invoked within the operator new() and operator delete() methods, respectively.
typedef void * (*vzMemoryAllocationCallback) (size_t nbytes, void *userData);
typedef void (*vzMemoryDeletionCallback) (void *dataPtr, void *userData);
The following method sets the memory allocation and de-allocation routines to use the mpkMalloc() and mpkFree() functions respectively.
// Set the allocation and de-allocation callback functions
vzMemory::setMemoryManagementCallbacks(allocate, deallocate, NULL);

// The allocator callback function
void *allocate(size_t size, void *userData) {

   return mpkMalloc(size);
}

// The de-allocator callback function
void deallocate(void *pointer, void *userData) {

   mpkFree(pointer);
}       

Back to Index