XBinder  Version 2.9.x
Macros | Functions
Memory Allocation Macros and Functions

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

Macros

#define OSRTALLOCTYPE(pctxt, type)   (type*) rtxMemHeapAlloc (&(pctxt)->pMemHeap, sizeof(type))
 This macro allocates a single element of the given type. More...
 
#define OSRTALLOCTYPEZ(pctxt, type)   (type*) rtxMemHeapAllocZ (&(pctxt)->pMemHeap, sizeof(type))
 This macro allocates and zeros a single element of the given type. More...
 
#define OSRTREALLOCARRAY(pctxt, pseqof, type)
 Reallocate an array. More...
 
#define rtxMemAlloc(pctxt, nbytes)   rtxMemHeapAlloc(&(pctxt)->pMemHeap,nbytes)
 Allocate memory. More...
 
#define rtxMemSysAlloc(pctxt, nbytes)   rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,nbytes)
 This macro makes a direct call to the configured system memory allocation function. More...
 
#define rtxMemAllocZ(pctxt, nbytes)   rtxMemHeapAllocZ(&(pctxt)->pMemHeap,nbytes)
 Allocate and zero memory. More...
 
#define rtxMemSysAllocZ(pctxt, nbytes)   rtxMemHeapSysAllocZ(&(pctxt)->pMemHeap,nbytes)
 Allocate and zero memory. More...
 
#define rtxMemRealloc(pctxt, mem_p, nbytes)   rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, nbytes)
 Reallocate memory. More...
 
#define rtxMemSysRealloc(pctxt, mem_p, nbytes)   rtxMemHeapSysRealloc(&(pctxt)->pMemHeap,(void*)mem_p,nbytes)
 This macro makes a direct call to the configured system memory reallocation function to do the reallocation. More...
 
#define rtxMemFreePtr(pctxt, mem_p)   rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
 Free memory pointer. More...
 
#define rtxMemSysFreePtr(pctxt, mem_p)   rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
 This macro makes a direct call to the configured system memory free function. More...
 
#define rtxMemAllocType(pctxt, ctype)   (ctype*)rtxMemHeapAlloc(&(pctxt)->pMemHeap,sizeof(ctype))
 Allocate type. More...
 
#define rtxMemSysAllocType(pctxt, ctype)   (ctype*)rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,sizeof(ctype))
 Allocate type. More...
 
#define rtxMemAllocTypeZ(pctxt, ctype)   (ctype*)rtxMemHeapAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))
 Allocate type and zero memory. More...
 
#define rtxMemSysAllocTypeZ(pctxt, ctype)   (ctype*)rtxMemHeapSysAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))
 Allocate type and zero memory. More...
 
#define rtxMemFreeType(pctxt, mem_p)   rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
 Free memory pointer. More...
 
#define rtxMemSysFreeType(pctxt, mem_p)   rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
 Free memory pointer. More...
 
#define rtxMemAllocArray(pctxt, n, type)   (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), 0)
 Allocate a dynamic array. More...
 
#define rtxMemSysAllocArray(pctxt, n, type)   (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), RT_MH_SYSALLOC)
 Allocate a dynamic array. More...
 
#define rtxMemAllocArrayZ(pctxt, n, type)   (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), RT_MH_ZEROARRAY)
 Allocate a dynamic array and zero memory. More...
 
#define rtxMemFreeArray(pctxt, mem_p)   rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
 Free memory pointer. More...
 
#define rtxMemSysFreeArray(pctxt, mem_p)   rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
 Free memory pointer. More...
 
#define rtxMemReallocArray(pctxt, mem_p, n, type)   (type*)rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, sizeof(type)*n)
 Reallocate memory. More...
 
#define rtxMemNewAutoPtr(pctxt, nbytes)   rtxMemHeapAlloc(&(pctxt)->pMemHeap, nbytes)
 This function allocates a new block of memory and creates an auto-pointer with reference count set to one. More...
 
#define rtxMemAutoPtrRef(pctxt, ptr)   rtxMemHeapAutoPtrRef(&(pctxt)->pMemHeap, (void*)(ptr))
 This function increments the auto-pointer reference count. More...
 
#define rtxMemAutoPtrUnref(pctxt, ptr)   rtxMemHeapAutoPtrUnref(&(pctxt)->pMemHeap, (void*)(ptr))
 This function decrements the auto-pointer reference count. More...
 
#define rtxMemAutoPtrGetRefCount(pctxt, ptr)   rtxMemHeapAutoPtrGetRefCount(&(pctxt)->pMemHeap, (void*)(ptr))
 This function returns the reference count of the given pointer. More...
 
#define rtxMemCheckPtr(pctxt, mem_p)   rtxMemHeapCheckPtr(&(pctxt)->pMemHeap, (void*)mem_p)
 Check memory pointer. More...
 
#define rtxMemCheck(pctxt)   rtxMemHeapCheck(&(pctxt)->pMemHeap, __FILE__, __LINE__)
 Check memory heap. More...
 
#define rtxMemPrint(pctxt)   rtxMemHeapPrint(&(pctxt)->pMemHeap)
 Print memory heap structure to stderr. More...
 
#define rtxMemPrintWithFree(pctxt)   rtxMemHeapPrintWithFree(&(pctxt)->pMemHeap)
 Print memory heap structure to stderr, the same as rtxMemPrint, but add details about the memory free list. More...
 
#define rtxMemSetProperty(pctxt, propId, pProp)   rtxMemHeapSetProperty (&(pctxt)->pMemHeap, propId, pProp)
 Set memory heap property. More...
 

Functions

EXTERNRT void rtxMemHeapPrint (void **ppvMemHeap)
 Print details about the memory heap.
 
EXTERNRT void rtxMemHeapPrintWithFree (void **ppvMemHeap)
 Print the same details about the memory heap as rtxMemHeapPrint but add deatils about the free memory list.
 
EXTERNRT int rtxMemHeapCreate (void **ppvMemHeap)
 This function creates a standard memory heap. More...
 
EXTERNRT int rtxMemHeapCreateExt (void **ppvMemHeap, OSMallocFunc malloc_func, OSReallocFunc realloc_func, OSFreeFunc free_func)
 This function creates a standard memory heap and sets the low-level memory functions to the specified values. More...
 
EXTERNRT int rtxMemStaticHeapCreate (void **ppvMemHeap, void *pmem, OSSIZE memsize)
 This function creates a static memory heap. More...
 
EXTERNRT int rtxMemHeapConvertStatic (void **ppvMemHeap, void *pmem, OSSIZE memsize)
 This function converts a standard memory heap to a static memory heap. More...
 
EXTERNRT void rtxMemSetAllocFuncs (OSMallocFunc malloc_func, OSReallocFunc realloc_func, OSFreeFunc free_func)
 This function sets the pointers to standard allocation functions. More...
 
EXTERNRT OSUINT32 rtxMemHeapGetDefBlkSize (OSCTXT *pctxt)
 This function returns the actual granularity of memory blocks in the context. More...
 
EXTERNRT void rtxMemSetDefBlkSize (OSUINT32 blkSize)
 This function sets the minimum size and the granularity of memory blocks for newly created memory heaps. More...
 
EXTERNRT OSUINT32 rtxMemGetDefBlkSize (OSVOIDARG)
 This function returns the actual granularity of memory blocks. More...
 
EXTERNRT OSBOOL rtxMemHeapIsEmpty (OSCTXT *pctxt)
 This function determines if the memory heap defined in the give context is empty (i.e. More...
 
EXTERNRT OSBOOL rtxMemIsZero (const void *pmem, OSSIZE memsiz)
 This helper function determines if an arbitrarily sized block of memory is set to zero. More...
 
EXTERNRT void rtxMemFree (OSCTXT *pctxt)
 Free memory associated with a context. More...
 
EXTERNRT void rtxMemReset (OSCTXT *pctxt)
 Reset memory associated with a context. More...
 

Detailed Description

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

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

Macro Definition Documentation

◆ OSRTALLOCTYPE

#define OSRTALLOCTYPE (   pctxt,
  type 
)    (type*) rtxMemHeapAlloc (&(pctxt)->pMemHeap, 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 77 of file rtxMemory.h.

◆ OSRTALLOCTYPEZ

#define OSRTALLOCTYPEZ (   pctxt,
  type 
)    (type*) rtxMemHeapAllocZ (&(pctxt)->pMemHeap, 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 86 of file rtxMemory.h.

◆ OSRTREALLOCARRAY

#define OSRTREALLOCARRAY (   pctxt,
  pseqof,
  type 
)
Value:
do {\
if (sizeof(type)*(pseqof)->n < (pseqof)->n) return RTERR_NOMEM; \
if (((pseqof)->elem = (type*) rtxMemHeapRealloc \
(&(pctxt)->pMemHeap, (pseqof)->elem, sizeof(type)*(pseqof)->n)) == 0) \
return RTERR_NOMEM; \
} while (0)
#define RTERR_NOMEM
No dynamic memory available.
Definition: rtxErrCodes.h:135

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 100 of file rtxMemory.h.

◆ rtxMemAlloc

#define rtxMemAlloc (   pctxt,
  nbytes 
)    rtxMemHeapAlloc(&(pctxt)->pMemHeap,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 350 of file rtxMemory.h.

◆ rtxMemAllocArray

#define rtxMemAllocArray (   pctxt,
  n,
  type 
)    (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), 0)

Allocate a dynamic array.

This macro allocates a dynamic array of records of the given type. The pointer to the allocated array is returned to the caller.

Parameters
pctxt- Pointer to a context block
n- Number of records to allocate
type- Data type of an array record

Definition at line 577 of file rtxMemory.h.

◆ rtxMemAllocArrayZ

#define rtxMemAllocArrayZ (   pctxt,
  n,
  type 
)    (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), RT_MH_ZEROARRAY)

Allocate a dynamic array and zero memory.

This macro allocates a dynamic array of records of the given type and writes zeros over the allocated memory. The pointer to the allocated array is returned to the caller.

Parameters
pctxt- Pointer to a context block
n- Number of records to allocate
type- Data type of an array record

Definition at line 608 of file rtxMemory.h.

◆ rtxMemAllocType

#define rtxMemAllocType (   pctxt,
  ctype 
)    (ctype*)rtxMemHeapAlloc(&(pctxt)->pMemHeap,sizeof(ctype))

Allocate type.

This macro allocates memory to hold a variable of the given type.

Parameters
pctxt- Pointer to a context block
ctype- Name of C typedef
Returns
- Pointer to allocated memory or NULL if insufficient memory was available to fulfill the request.

Definition at line 493 of file rtxMemory.h.

◆ rtxMemAllocTypeZ

#define rtxMemAllocTypeZ (   pctxt,
  ctype 
)    (ctype*)rtxMemHeapAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))

Allocate type and zero memory.

This macro allocates memory to hold a variable of the given type and initializes the allocated memory to zero.

Parameters
pctxt- Pointer to a context block
ctype- Name of C typedef
Returns
- Pointer to allocated memory or NULL if insufficient memory was available to fulfill the request.

Definition at line 521 of file rtxMemory.h.

◆ rtxMemAllocZ

#define rtxMemAllocZ (   pctxt,
  nbytes 
)    rtxMemHeapAllocZ(&(pctxt)->pMemHeap,nbytes)

Allocate and zero memory.

This macro allocates the given number of bytes and then initializes the memory block to zero.

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 375 of file rtxMemory.h.

◆ rtxMemAutoPtrGetRefCount

#define rtxMemAutoPtrGetRefCount (   pctxt,
  ptr 
)    rtxMemHeapAutoPtrGetRefCount(&(pctxt)->pMemHeap, (void*)(ptr))

This function returns the reference count of the given pointer.

goes to zero, the memory is freed.

Parameters
pctxtPointer to a context structure.
ptrPointer on which reference count is to be fetched.
Returns
Pointer reference count.

Definition at line 704 of file rtxMemory.h.

◆ rtxMemAutoPtrRef

#define rtxMemAutoPtrRef (   pctxt,
  ptr 
)    rtxMemHeapAutoPtrRef(&(pctxt)->pMemHeap, (void*)(ptr))

This function increments the auto-pointer reference count.

Parameters
pctxtPointer to a context structure.
ptrPointer on which reference count is to be incremented.
Returns
Referenced pointer value (ptr argument) or NULL if reference count could not be incremented.

Definition at line 680 of file rtxMemory.h.

◆ rtxMemAutoPtrUnref

#define rtxMemAutoPtrUnref (   pctxt,
  ptr 
)    rtxMemHeapAutoPtrUnref(&(pctxt)->pMemHeap, (void*)(ptr))

This function decrements the auto-pointer reference count.

If the count goes to zero, the memory is freed.

Parameters
pctxtPointer to a context structure.
ptrPointer on which reference count is to be decremented.
Returns
Positive reference count or a negative error code. If zero, memory held by pointer will have been freed.

Definition at line 693 of file rtxMemory.h.

◆ rtxMemCheck

#define rtxMemCheck (   pctxt)    rtxMemHeapCheck(&(pctxt)->pMemHeap, __FILE__, __LINE__)

Check memory heap.

Parameters
pctxt- Pointer to a context block

Definition at line 723 of file rtxMemory.h.

◆ rtxMemCheckPtr

#define rtxMemCheckPtr (   pctxt,
  mem_p 
)    rtxMemHeapCheckPtr(&(pctxt)->pMemHeap, (void*)mem_p)

Check memory pointer.

This macro check pointer on presence in heap.

Parameters
pctxt- Pointer to a context block
mem_p- Pointer to memory block.
Returns
1 - pointer refer to memory block in heap; 0 - poiter refer not memory heap block.

Definition at line 715 of file rtxMemory.h.

◆ rtxMemFreeArray

#define rtxMemFreeArray (   pctxt,
  mem_p 
)    rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)

Free memory pointer.

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

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

Definition at line 622 of file rtxMemory.h.

◆ rtxMemFreePtr

#define rtxMemFreePtr (   pctxt,
  mem_p 
)    rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)

Free memory pointer.

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

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

Definition at line 442 of file rtxMemory.h.

◆ rtxMemFreeType

#define rtxMemFreeType (   pctxt,
  mem_p 
)    rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)

Free memory pointer.

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

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

Definition at line 551 of file rtxMemory.h.

◆ rtxMemNewAutoPtr

#define rtxMemNewAutoPtr (   pctxt,
  nbytes 
)    rtxMemHeapAlloc(&(pctxt)->pMemHeap, nbytes)

This function allocates a new block of memory and creates an auto-pointer with reference count set to one.

The rtxMemAutoPtrRef and rtxMemAutoPtrUnref functions can be used to increment and decrement the reference count. When the count goes to zero, the memory held by the pointer is freed.

Parameters
pctxtPointer to a context structure.
nbytesNumber of bytes to allocate.
Returns
Pointer to allocated memory or NULL if not enough memory is available.

Definition at line 669 of file rtxMemory.h.

◆ rtxMemPrint

#define rtxMemPrint (   pctxt)    rtxMemHeapPrint(&(pctxt)->pMemHeap)

Print memory heap structure to stderr.

Parameters
pctxt- Pointer to a context block

Definition at line 731 of file rtxMemory.h.

◆ rtxMemPrintWithFree

#define rtxMemPrintWithFree (   pctxt)    rtxMemHeapPrintWithFree(&(pctxt)->pMemHeap)

Print memory heap structure to stderr, the same as rtxMemPrint, but add details about the memory free list.

Parameters
pctxt- Pointer to a context block

Definition at line 740 of file rtxMemory.h.

◆ rtxMemRealloc

#define rtxMemRealloc (   pctxt,
  mem_p,
  nbytes 
)    rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, 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
mem_p- Pointer to memory block to reallocate. This must have been allocated using the rtxMemAlloc 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 mem_p pointer that was passed in if the block did not need to be relocated.

Definition at line 409 of file rtxMemory.h.

◆ rtxMemReallocArray

#define rtxMemReallocArray (   pctxt,
  mem_p,
  n,
  type 
)    (type*)rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, sizeof(type)*n)

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
mem_p- Pointer to memory block to reallocate. This must have been allocated using the rtxMemAlloc macro or the rtxMemHeapAlloc function.
n- Number of items of the given type to be allocated.
type- Array element data type (for example, int).
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 653 of file rtxMemory.h.

◆ rtxMemSetProperty

#define rtxMemSetProperty (   pctxt,
  propId,
  pProp 
)    rtxMemHeapSetProperty (&(pctxt)->pMemHeap, propId, pProp)

Set memory heap property.

Parameters
pctxt- Pointer to a context block
propId- Property Id.
pProp- Pointer to property value.

Definition at line 750 of file rtxMemory.h.

◆ rtxMemSysAlloc

#define rtxMemSysAlloc (   pctxt,
  nbytes 
)    rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,nbytes)

This macro makes a direct call to the configured system memory allocation function.

By default, this is the C malloc function, but it is possible to configure to use a custom allocation 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 363 of file rtxMemory.h.

◆ rtxMemSysAllocArray

#define rtxMemSysAllocArray (   pctxt,
  n,
  type 
)    (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), RT_MH_SYSALLOC)

Allocate a dynamic array.

This macro allocates a dynamic array of records of the given type. The pointer to the allocated array is returned to the caller.

This macro makes a direct call to the configured system memory allocation function. By default, this is the C malloc function, but it is possible to configure to use a custom allocation function.

Parameters
pctxt- Pointer to a context block
n- Number of records to allocate
type- Data type of an array record

Definition at line 596 of file rtxMemory.h.

◆ rtxMemSysAllocType

#define rtxMemSysAllocType (   pctxt,
  ctype 
)    (ctype*)rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,sizeof(ctype))

Allocate type.

This macro allocates memory to hold a variable of the given type.

This macro makes a direct call to the configured system memory allocation function. By default, this is the C malloc function, but it is possible to configure to use a custom allocation function.

Parameters
pctxt- Pointer to a context block
ctype- Name of C typedef
Returns
- Pointer to allocated memory or NULL if insufficient memory was available to fulfill the request.

Definition at line 509 of file rtxMemory.h.

◆ rtxMemSysAllocTypeZ

#define rtxMemSysAllocTypeZ (   pctxt,
  ctype 
)    (ctype*)rtxMemHeapSysAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))

Allocate type and zero memory.

This macro allocates memory to hold a variable of the given type and initializes the allocated memory to zero.

This macro makes a direct call to the configured system memory allocation function. By default, this is the C malloc function, but it is possible to configure to use a custom allocation function.

Parameters
pctxt- Pointer to a context block
ctype- Name of C typedef
Returns
- Pointer to allocated memory or NULL if insufficient memory was available to fulfill the request.

Definition at line 537 of file rtxMemory.h.

◆ rtxMemSysAllocZ

#define rtxMemSysAllocZ (   pctxt,
  nbytes 
)    rtxMemHeapSysAllocZ(&(pctxt)->pMemHeap,nbytes)

Allocate and zero memory.

This macro allocates the given number of bytes and then initializes the memory block to zero.

This macro makes a direct call to the configured system memory allocation function. By default, this is the C malloc function, but it is possible to configure to use a custom allocation 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 391 of file rtxMemory.h.

◆ rtxMemSysFreeArray

#define rtxMemSysFreeArray (   pctxt,
  mem_p 
)    rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)

Free memory pointer.

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

Parameters
pctxt- Pointer to a context block
mem_p- Pointer to memory block to free. This must have been allocated using the rtxMemSysAlloc or rtxMemSysAlloc macro or the rtxMemSysHeapAlloc function.

Definition at line 636 of file rtxMemory.h.

◆ rtxMemSysFreePtr

#define rtxMemSysFreePtr (   pctxt,
  mem_p 
)    rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)

This macro makes a direct call to the configured system memory free function.

By default, this is the C free function, but it is possible to configure to use a custom free function.

Parameters
pctxt- Pointer to a context block
mem_p- Pointer to memory block to free. This must have been allocated using the rtxMemSysAlloc macro or the rtxMemHeapSysAlloc function.

Definition at line 455 of file rtxMemory.h.

◆ rtxMemSysFreeType

#define rtxMemSysFreeType (   pctxt,
  mem_p 
)    rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)

Free memory pointer.

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

Parameters
pctxt- Pointer to a context block
mem_p- Pointer to memory block to free. This must have been allocated using the rtxMemSysAlloc or rtxMemSysAlloc macro or the rtxMemSysHeapAlloc function.

Definition at line 565 of file rtxMemory.h.

◆ rtxMemSysRealloc

#define rtxMemSysRealloc (   pctxt,
  mem_p,
  nbytes 
)    rtxMemHeapSysRealloc(&(pctxt)->pMemHeap,(void*)mem_p,nbytes)

This macro makes a direct call to the configured system memory reallocation function to do the reallocation.

. By default, this is the C realloc function, but it is possible to configure to use a custom reallocation function.

Parameters
pctxt- Pointer to a context block
mem_p- Pointer to memory block to reallocate. This must have been allocated using the rtxMemSysAlloc macro or the rtxMemHeapSysAlloc 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 mem_p pointer that was passed in if the block did not need to be relocated.

Definition at line 428 of file rtxMemory.h.

Function Documentation

◆ rtxMemFree()

EXTERNRT void rtxMemFree ( OSCTXT pctxt)

Free memory associated with a context.

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

Parameters
pctxt- Pointer to a context block

◆ rtxMemGetDefBlkSize()

EXTERNRT OSUINT32 rtxMemGetDefBlkSize ( OSVOIDARG  )

This function returns the actual granularity of memory blocks.

Returns
The currently used minimum size and the granularity of memory blocks.

◆ rtxMemHeapConvertStatic()

EXTERNRT int rtxMemHeapConvertStatic ( void **  ppvMemHeap,
void *  pmem,
OSSIZE  memsize 
)

This function converts a standard memory heap to a static memory heap.

All allocations are done from the static block of memory that is provided. It is much faster than the standard management but has some limitations such as the inability to free individual pointer values. All memory in the block must be freed at once.

If memory was previously allocated using the given heap, it will be freed before conversion.

Parameters
ppvMemHeapPointer-to-pointer to heap variable. ppvMemHeap and *ppvMemHeap must not be null; otherwise, an error is returned.
pmemPointer to static memory block to use for allocations.
memsizeSizeof the memory block in bytes.
Returns
Status of the creation operation: 0 = success or < 0 for an error.

◆ rtxMemHeapCreate()

EXTERNRT int rtxMemHeapCreate ( void **  ppvMemHeap)

This function creates a standard memory heap.

It is invoked internally from the rtxInitContext function to create the heap in the context.

Parameters
ppvMemHeapPointer-to-pointer to variable to receive created object.
Returns
Status of the creation operation: 0 = success or RTERR-NOMEM if no memory available.

◆ rtxMemHeapCreateExt()

EXTERNRT int rtxMemHeapCreateExt ( void **  ppvMemHeap,
OSMallocFunc  malloc_func,
OSReallocFunc  realloc_func,
OSFreeFunc  free_func 
)

This function creates a standard memory heap and sets the low-level memory functions to the specified values.

It is invoked internally from the rtxInitContextExt function to create the heap in the context.

Parameters
ppvMemHeapPointer-to-pointer to variable to receive created object.
malloc_funcPointer to memory allocation function.
realloc_funcPointer to memory reallocation function.
free_funcPointer to memory free function.
Returns
Status of the creation operation: 0 = success or RTERR-NOMEM if no memory available.

◆ rtxMemHeapGetDefBlkSize()

EXTERNRT OSUINT32 rtxMemHeapGetDefBlkSize ( OSCTXT pctxt)

This function returns the actual granularity of memory blocks in the context.

Parameters
pctxtPointer to a context block.

◆ rtxMemHeapIsEmpty()

EXTERNRT OSBOOL rtxMemHeapIsEmpty ( OSCTXT pctxt)

This function determines if the memory heap defined in the give context is empty (i.e.

contains no outstanding memory allocations).

Parameters
pctxtPointer to a context block.
Returns
Boolean true value if heap is empty.

◆ rtxMemIsZero()

EXTERNRT OSBOOL rtxMemIsZero ( const void *  pmem,
OSSIZE  memsiz 
)

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

Parameters
pmemPointer to memory block to check
memsizSize of the memory block
Returns
Boolean result: true if memory is all zero

◆ rtxMemReset()

EXTERNRT void rtxMemReset ( OSCTXT pctxt)

Reset memory associated with a context.

This macro resets all memory held within a context. This is all memory allocated using the rtxMemAlloc (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

◆ rtxMemSetAllocFuncs()

EXTERNRT 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_funcPointer to the memory allocation function ('malloc' by default).
realloc_funcPointer to the memory reallocation function ('realloc' by default).
free_funcPointer to the memory deallocation function ('free' by default).

◆ rtxMemSetDefBlkSize()

EXTERNRT void rtxMemSetDefBlkSize ( OSUINT32  blkSize)

This function sets the minimum size and the granularity of memory blocks for newly created memory heaps.

Parameters
blkSizeThe minimum size and the granularity of memory blocks.

◆ rtxMemStaticHeapCreate()

EXTERNRT int rtxMemStaticHeapCreate ( void **  ppvMemHeap,
void *  pmem,
OSSIZE  memsize 
)

This function creates a static memory heap.

All allocations are done from the static block of memory that is provided. It is much faster than the standard management but has some limitations such as the inability to free individual pointer values. All memory in the block must be freed at once.

Note: rtxMemHeapConvertStatic is generally preferrable to rtxMemStaticHeapCreate, since in most cases you will already have a heap object that you can reuse.

Parameters
ppvMemHeapPointer-to-pointer to variable to receive created object.
pmemPointer to static memory block to use for allocations.
memsizeSizeof the memory block in bytes.
Returns
Status of the creation operation: 0 = success or RTERR-NOMEM if no memory available.