Objective Systems, Inc.  
Home
About ASN.1
Products
Free Software
Documents
Services
Resources
Resellers
Customers
Careers
About Us
Contact Us
 

Google


Objective Systems, Inc.

Memory Allocation Macros and Functions

Memory allocation functions and macros handle memory management for the XBinder C run-time. More...

Defines

#define OSRTALLOCTYPE(pctxt, type)   (type*) rtxMemHeapAlloc (&(pctxt)->pTypeMemHeap, sizeof(type))
 This macro allocates a single element of the given type.
#define OSRTALLOCTYPEZ(pctxt, type)   (type*) rtxMemHeapAllocZ (&(pctxt)->pTypeMemHeap, sizeof(type))
 This macro allocates and zeros a single element of the given type.
#define OSRTARRAYSIZE(x)   (sizeof(x)/sizeof(x[0]))
 This macro returns the number of elements in an array.
#define OSCRTMALLOC0(nbytes)   malloc(nbytes)
#define OSCRTFREE0(ptr)   free(ptr)
#define OSCRTMALLOC   OSMALLOC
#define OSCRTFREE   OSFREEPTR
#define OSCDECL
#define rtxMemAllocType(pctxt, type)   (type*) rtxMemAllocZ ((pctxt), sizeof(type))

Typedefs

typedef void *OSCDECL * OSMallocFunc (size_t size)
typedef void *OSCDECL * OSReallocFunc (void *ptr, size_t size)

Functions

void rtxMemSetAllocFuncs (OSMallocFunc malloc_func, OSReallocFunc realloc_func, OSFreeFunc free_func)
 This function sets the pointers to standard allocation functions.
OSBOOL rtxMemIsZero (const void *pmem, size_t memsiz)
 This helper function determines if an arbitrarily sized block of memory is set to zero.
void * rtxMemAlloc (OSCTXT *pctxt, size_t nbytes)
 This function allocates dynamic memory.
void * rtxMemAllocZ (OSCTXT *pctxt, size_t nbytes)
 This function allocates dynamic memory and sets the allocated buffer to zero.
void rtxMemFree (OSCTXT *pctxt)
 This function frees all memory associated with a given context.
void rtxMemFreePtr (OSCTXT *pctxt, void *mem_p)
 This function frees dynamic memory that was previously allocated by a call to the rtxMemAlloc, rtxMemAllocZ, or rtxMemRealloc memory allocation functions (or associated macros).
void * rtxMemRealloc (OSCTXT *pctxt, void *mem_p, size_t oldnbytes, size_t nbytes)
 This function changes the size of an allocated dynamic memory segment.

Detailed Description

Memory allocation functions and macros handle memory management for the XBinder C run-time.

Special algorithms are used for allocation and deallocation of memory to improve the run-time performance.


Define Documentation

#define OSRTALLOCTYPE pctxt,
type   )     (type*) rtxMemHeapAlloc (&(pctxt)->pTypeMemHeap, sizeof(type))
 

This macro allocates a single element of the given type.

Parameters:
pctxt - Pointer to a context block
type - Data type of record to allocate

Definition at line 59 of file rtxMemory.h.

#define OSRTALLOCTYPEZ pctxt,
type   )     (type*) rtxMemHeapAllocZ (&(pctxt)->pTypeMemHeap, sizeof(type))
 

This macro allocates and zeros a single element of the given type.

Parameters:
pctxt - Pointer to a context block
type - Data type of record to allocate

Definition at line 68 of file rtxMemory.h.

#define OSRTARRAYSIZE  )     (sizeof(x)/sizeof(x[0]))
 

This macro returns the number of elements in an array.

Parameters:
x - Array varaible

Definition at line 76 of file rtxMemory.h.


Function Documentation

void* rtxMemAlloc OSCTXT pctxt,
size_t  nbytes
 

This function allocates dynamic memory.

The rtxMemFree or rtxMemFreePtr function should be used to release the allocated memory.

Parameters:
pctxt Pointer to a context block
nbytes The number of bytes of dynamic memory to allocate.
Returns:
A pointer to the allocated memory. The rtxMemFreePtr should be called to release the allocated memory.

void* rtxMemAllocZ OSCTXT pctxt,
size_t  nbytes
 

This function allocates dynamic memory and sets the allocated buffer to zero.

The rtxMemFree or rtxMemFreePtr function should be used to release the allocated memory.

Parameters:
pctxt Pointer to a context block
nbytes The number of bytes of dynamic memory to allocate.
Returns:
A pointer to the allocated memory. The rtxMemFreePtr should be called to release the allocated memory.

void rtxMemFree OSCTXT pctxt  ) 
 

This function frees all memory associated with a given context.

This is all memory allocated using the rtxMemAlloc, rtxMemAllocZ, or rtxMemRealloc memory allocation functions (or associated macros) using the given context variable.

Parameters:
pctxt Pointer to a context block

void rtxMemFreePtr OSCTXT pctxt,
void *  mem_p
 

This function frees dynamic memory that was previously allocated by a call to the rtxMemAlloc, rtxMemAllocZ, or rtxMemRealloc memory allocation functions (or associated macros).

Parameters:
pctxt Pointer to a context block
mem_p A pointer to previously allocated memory.

OSBOOL rtxMemIsZero const void *  pmem,
size_t  memsiz
 

This helper function determines if an arbitrarily sized block of memory is set to zero.

Parameters:
pmem Pointer to memory block to check
memsiz Size of the memory block
Returns:
Boolean result: true if memory is all zero

void* rtxMemRealloc OSCTXT pctxt,
void *  mem_p,
size_t  oldnbytes,
size_t  nbytes
 

This function changes the size of an allocated dynamic memory segment.

The mem_p argument points to the beginning of a memory block. If mem_p is NULL, rtxMemRealloc behaves the same way as rtxMemAlloc and allocates a new block of nbytes. If mem_p is not NULL, it must be a pointer returned by a previous call to rtxMemAlloc, or rtxMemRealloc; it cannot point to memory allocated in any other way.

Parameters:
pctxt Pointer to a context block
mem_p A pointer to previously allocated memory.
oldnbytes The number of bytes already allocated.
nbytes The number of bytes of dynamic memory to allocate.
Returns:
A pointer to the allocated memory. The rtxMemFreePtr should be called to release the allocated memory.

void rtxMemSetAllocFuncs OSMallocFunc  malloc_func,
OSReallocFunc  realloc_func,
OSFreeFunc  free_func
 

This function sets the pointers to standard allocation functions.

These functions are used to allocate/reallocate/free memory blocks. By default, standard C functions - 'malloc', 'realloc' and 'free' - are used. But if some platforms do not support these functions (or some other reasons exist) they can be overloaded. The functions being overloaded should have the same prototypes as the standard functions.

Parameters:
malloc_func Pointer to the memory allocation function ('malloc' by default).
realloc_func Pointer to the memory reallocation function ('realloc' by default).
free_func Pointer to the memory deallocation function ('free' by default).


This file was last modified on 8 Jan 2007.
XBinder, Version 1.1.9