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*) rtxMemHeapAllocZ (&(pctxt)->pTypeMemHeap, sizeof(type))
 This macro allocates and zeros a single element of the given type.

#define OSRTALLOCOCTETARRAY(pctxt, n)   (OSOCTET*) rtxMemHeapAllocZ (&(pctxt)->pTypeMemHeap, n)
#define OSRTALLOCTYPEARRAY(pctxt, type, n)   (type*) rtxMemHeapAllocZ (&(pctxt)->pTypeMemHeap, n * sizeof(type))
#define OSRTALLOCELEMDNODE(pctxt, type)
#define OSRTALLOCELEMSNODE(pctxt, type)
#define OSRTARRAYSIZE(x)   (sizeof(x)/sizeof(x[0]))
 Get array size.

#define OSMALLOC(pctxt, nbytes)   rtxMemHeapAlloc(&(pctxt)->pTypeMemHeap, nbytes)
 Allocate memory.

#define OSMALLOCZ(pctxt, nbytes)   rtxMemHeapAllocZ(&(pctxt)->pTypeMemHeap, nbytes)
#define OSREALLOC(pctxt, pmem, nbytes)   rtxMemHeapRealloc(&(pctxt)->pTypeMemHeap, pmem, nbytes)
 Reallocate memory.

#define OSRTREALLOCARRAY(pctxt, pseqof, type)
 Reallocate an array.

#define OSMEMFREE(pctxt)   rtxMemHeapFreeAll(&(pctxt)->pTypeMemHeap)
 Free memory associated with a context.

#define OSFREEPTR(pctxt, pmem)   rtxMemHeapFreePtr(&(pctxt)->pTypeMemHeap, (void*)pmem)
 Free memory pointer.

#define OSMEMRESET(pctxt)   rtxMemHeapReset(&(pctxt)->pTypeMemHeap)
 Reset memory associated with a context.

#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

typedef void (OSCDECL *OSFreeFunc)(void *ptr)
void rtxMemHeapAddRef (void **ppvMemHeap)
void * rtxMemHeapAlloc (void **ppvMemHeap, size_t nbytes)
void * rtxMemHeapAllocZ (void **ppvMemHeap, size_t nbytes)
int rtxMemHeapCheckPtr (void **ppvMemHeap, void *mem_p)
int rtxMemHeapCreate (void **ppvMemHeap)
void rtxMemHeapFreeAll (void **ppvMemHeap)
void rtxMemHeapFreePtr (void **ppvMemHeap, void *mem_p)
void * rtxMemHeapMarkSaved (void **ppvMemHeap, const void *mem_p, OSBOOL saved)
void * rtxMemHeapRealloc (void **ppvMemHeap, void *mem_p, size_t nbytes_)
void rtxMemHeapRelease (void **ppvMemHeap)
void rtxMemHeapReset (void **ppvMemHeap)
void rtxMemHeapSetProperty (void **ppvMemHeap, OSUINT32 propId, void *pProp)
void rtxMemSetAllocFuncs (OSMallocFunc malloc_func, OSReallocFunc realloc_func, OSFreeFunc free_func)
 This function sets the pointers to standard allocation functions.

void rtxMemFreeOpenSeqExt (OSCTXT *pctxt, struct OSRTDList *pElemList)
void rtxMemHeapSetFlags (OSCTXT *pctxt, OSUINT32 flags)
void rtxMemHeapClearFlags (OSCTXT *pctxt, OSUINT32 flags)
void rtxMemHeapSetDefBlkSize (OSCTXT *pctxt, OSUINT32 blkSize)
 This function sets the pointer to standard allocation functions.

OSUINT32 rtxMemHeapGetDefBlkSize (OSCTXT *pctxt)
 This function returns the actual granularity of memory blocks.

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 allocated dynamic memory.

void * rtxMemAllocZ (OSCTXT *pctxt, size_t nbytes)
 This function allocated dynamic memory and sets the allocated buffer to zero.

void rtxMemFreePtr (OSCTXT *pctxt, void *mem_p)
 This function frees dynamic memory that was previously allocated by a call to rtxMemAlloc, rtxMemAllocZ, or rtxMemRealloc.

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 OSFREEPTR pctxt,
pmem   )     rtxMemHeapFreePtr(&(pctxt)->pTypeMemHeap, (void*)pmem)
 

Free memory pointer.

This macro frees memory at the given pointer. The memory must have been allocated using the OSMALLOC (or similar) macros or the rtxMem memory allocation functions. This macro is similar to the C free function.

Parameters:
pctxt - Pointer to a context block
pmem - Pointer to memory block to free. This must have been allocated using the OSMALLOC macro or the rtxMemHeapAlloc function.

Definition at line 159 of file rtxMemory.h.

#define OSMALLOC pctxt,
nbytes   )     rtxMemHeapAlloc(&(pctxt)->pTypeMemHeap, nbytes)
 

Allocate memory.

This macro allocates the given number of bytes. It is similar to the C malloc run-time function.

Parameters:
pctxt - Pointer to a context block
nbytes - Number of bytes of memory to allocate
Returns:
- Void pointer to allocated memory or NULL if insufficient memory was available to fulfill the request.

Definition at line 93 of file rtxMemory.h.

#define OSMEMFREE pctxt   )     rtxMemHeapFreeAll(&(pctxt)->pTypeMemHeap)
 

Free memory associated with a context.

This macro frees all memory held within a context. This is all memory allocated using the OSMALLOC (and similar macros) and the rtxMem memory allocation functions using the given context variable.

Parameters:
pctxt - Pointer to a context block

Definition at line 145 of file rtxMemory.h.

#define OSMEMRESET pctxt   )     rtxMemHeapReset(&(pctxt)->pTypeMemHeap)
 

Reset memory associated with a context.

This macro resets all memory held within a context. This is all memory allocated using the OSMALLOC (and similar macros) and the rtxMem memory allocation functions using the given context variable.

The difference between this and the OSMEMFREE macro is that the memory blocks held within the context are not actually freed. Internal pointers are reset so the existing blocks can be reused. This can provide a performace improvement for repetitive tasks such as decoding messages in a loop.

Parameters:
pctxt - Pointer to a context block

Definition at line 175 of file rtxMemory.h.

#define OSREALLOC pctxt,
pmem,
nbytes   )     rtxMemHeapRealloc(&(pctxt)->pTypeMemHeap, pmem, nbytes)
 

Reallocate memory.

This macro reallocates a memory block (either expands or contracts) to the given number of bytes. It is similar to the C realloc run-time function.

Parameters:
pctxt - Pointer to a context block
pmem - Pointer to memory block to reallocate. This must have been allocated using the OSMALLOC macro or the rtxMemHeapAlloc function.
nbytes - Number of bytes of memory to which the block is to be resized.
Returns:
- Void pointer to allocated memory or NULL if insufficient memory was available to fulfill the request. This may be the same as the pmem pointer that was passed in if the block did not need to be relocated.

Definition at line 116 of file rtxMemory.h.

#define OSRTALLOCELEMDNODE pctxt,
type   ) 
 

Value:

(type*) (((char*)rtxMemHeapAllocZ (&(pctxt)->pTypeMemHeap, sizeof(type) + \
sizeof(OSRTDListNode))) + sizeof(OSRTDListNode))

Definition at line 68 of file rtxMemory.h.

#define OSRTALLOCELEMSNODE pctxt,
type   ) 
 

Value:

(type*) (((char*)rtxMemHeapAllocZ (&(pctxt)->pTypeMemHeap, sizeof(type) + \
sizeof(OSRTSListNode))) + sizeof(OSRTSListNode))

Definition at line 72 of file rtxMemory.h.

#define OSRTALLOCTYPE 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 59 of file rtxMemory.h.

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

Get array size.

This macro returns the number of elements in an array.

Parameters:
x - Array varaible

Definition at line 81 of file rtxMemory.h.

#define OSRTREALLOCARRAY pctxt,
pseqof,
type   ) 
 

Value:

do {\
if (sizeof(type)*(pseqof)->n < (pseqof)->n) return RTERR_NOMEM; \
if (((pseqof)->elem = (type*) rtxMemHeapRealloc \
(&(pctxt)->pTypeMemHeap, (pseqof)->elem, sizeof(type)*(pseqof)->n)) == 0) \
return RTERR_NOMEM; \
} while (0)
Reallocate an array.

This macro reallocates an array (either expands or contracts) to hold the given number of elements. The number of elements is specified in the n member variable of the pseqof argument.

Parameters:
pctxt - Pointer to a context block
pseqof - Pointer to a generated SEQUENCE OF array structure. The n member variable must be set to the number of records to allocate.
type - Data type of an array record

Definition at line 130 of file rtxMemory.h.


Function Documentation

void* rtxMemAlloc OSCTXT pctxt,
size_t  nbytes
 

This function allocated dynamic memory.

rtxMemFreePtr call can 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.

Referenced by OSXSDGlobalElement::memAlloc().

void* rtxMemAllocZ OSCTXT pctxt,
size_t  nbytes
 

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

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 rtxMemFreePtr OSCTXT pctxt,
void *  mem_p
 

This function frees dynamic memory that was previously allocated by a call to rtxMemAlloc, rtxMemAllocZ, or rtxMemRealloc.

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

Referenced by OSXSDGlobalElement::memFreePtr().

OSUINT32 rtxMemHeapGetDefBlkSize OSCTXT pctxt  ) 
 

This function returns the actual granularity of memory blocks.

Parameters:
pctxt Pointer to a context block.

void rtxMemHeapSetDefBlkSize OSCTXT pctxt,
OSUINT32  blkSize
 

This function sets the pointer to standard allocation functions.

These functions are used to allocate/reallocate/free the 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 standard ones.

Parameters:
pctxt Pointer to a context block.
blkSize The currently used minimum size and the granularity of memory blocks.

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 allocated 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 by 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.

Referenced by OSXSDGlobalElement::memRealloc().

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 the 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 standard ones.

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 1 Jun 2004.
XBinder, Version 1.0.0