DelegateMQ
Loading...
Searching...
No Matches
xallocator.cpp File Reference
#include "Allocator.h"
#include "xallocator.h"
#include "predef/util/Fault.h"
#include <cstring>
#include <iostream>
#include <mutex>

Macros

#define char_BIT   8
 
#define MAX_ALLOCATORS   15
 

Functions

template<class T >
nexthigher (T k)
 
void xalloc_init ()
 
void xalloc_destroy ()
 
Allocatorxallocator_get_allocator (size_t size)
 
void * xmalloc (size_t size)
 
void xfree (void *ptr)
 
void * xrealloc (void *oldMem, size_t size)
 
void xalloc_stats ()
 Output xallocator usage statistics.
 

Macro Definition Documentation

◆ char_BIT

#define char_BIT   8

◆ MAX_ALLOCATORS

#define MAX_ALLOCATORS   15

Function Documentation

◆ nexthigher()

template<class T >
T nexthigher ( T k)

Returns the next higher powers of two. For instance, pass in 12 and the value returned would be 16.

Parameters
[in]k- numeric value to compute the next higher power of two.
Returns
The next higher power of two based on the input k.

◆ xalloc_destroy()

void xalloc_destroy ( )

Called one time when the application exits to cleanup any allocated memory. ~XallocInitDestroy destructor calls this function automatically.

◆ xalloc_init()

void xalloc_init ( )

This function must be called exactly one time before any other xallocator API is called. XallocInitDestroy constructor calls this function automatically.

◆ xalloc_stats()

void xalloc_stats ( )

Output xallocator usage statistics.

Output allocator statistics to the standard output.

◆ xallocator_get_allocator()

Allocator * xallocator_get_allocator ( size_t size)

Get an Allocator instance based upon the client's requested block size. If a Allocator instance is not currently available to handle the size, then a new Allocator instance is create.

Parameters
[in]size- the client's requested block size.
Returns
An Allocator instance that handles blocks of the requested size.

◆ xfree()

void xfree ( void * ptr)

Frees a memory block previously allocated with xalloc. The blocks are returned to the fixed block allocator that originally created it.

Parameters
[in]ptr- a pointer to a block created with xalloc.

◆ xmalloc()

void * xmalloc ( size_t size)

Allocates a memory block of the requested size. The blocks are created from the fixed block allocators.

Parameters
[in]size- the client requested size of the block.
Returns
A pointer to the client's memory block.

◆ xrealloc()

void * xrealloc ( void * oldMem,
size_t size )

Reallocates a memory block previously allocated with xalloc.

Parameters
[in]ptr- a pointer to a block created with xalloc.
[in]size- the client requested block size to create.