Qualia  0.2
Static Public Member Functions | Static Private Attributes | List of all members
Alloc Class Reference

#include <Allocator.h>

Collaboration diagram for Alloc:
Collaboration graph
[legend]

Static Public Member Functions

static void * malloc (size_t size)
 
static void * calloc (size_t num, size_t size)
 
static void * realloc (void *ptr, size_t size)
 
static void free (void *ptr)
 
static void init (Allocator *alloc)
 
static Allocatorinstance ()
 

Static Private Attributes

static Allocatorinst = 0
 

Detailed Description

Static class for memory management. In Qualia, all dynamic memory allocation calls should use the Alloc static methods instead of the ones provided in the standard library. That allows code to be easily ported to AVR platform where static allocation is usually better (see StaticAllocator).

Example use (see class StaticAllocator).

#if is_computer()
Allocator allocator; // use standard allocator
#else
unsigned char STATIC_BUFFER[1000];
StaticAllocator allocator(&STATIC_BUFFER); // use static allocator
#endif
Alloc::init(&allocator);
int* val = (int*) Alloc::malloc(10*sizeof(int));
MyClass* obj = Q_NEW(MyClass)(1, 2); // MyClass* bbj = new MyClass(1,2);
MyClass* arr = Q_ARRAY_NEW(MyClass,10); // MyClass* arr = new MyClass[10];
...
Alloc::free(val);
Q_DELETE(MyClass, ptr);

Member Function Documentation

void * Alloc::calloc ( size_t  num,
size_t  size 
)
static
void Alloc::free ( void *  ptr)
static
void Alloc::init ( Allocator alloc)
static
static Allocator* Alloc::instance ( )
inlinestatic
void * Alloc::malloc ( size_t  size)
static
void * Alloc::realloc ( void *  ptr,
size_t  size 
)
static

Member Data Documentation

Allocator * Alloc::inst = 0
staticprivate

The documentation for this class was generated from the following files: