It is possible to replace the core memory management functions used
by the ASN1C run-time memory manager. This has the advantage of
preserving the existing management scheme but with the use of different
core functions. Using different core functions may be necessary on some
systems that do not have the standard C run-time functions
malloc
,
free
, and
realloc
, or when extra functionality is
desired.
To replace the core functions, use the
rtxMemSetAllocFuncs
runtime library call:
void rtxMemSetAllocFuncs (OSMallocFunc malloc_func, OSReallocFunc realloc_func, OSFreeFunc free_func);
The
malloc
,
realloc
, and
free
functions must have the same
prototype as the standard C functions. Some systems do not have a
realloc-like function. In this case,
realloc_func
may be set to NULL. This
will cause the
malloc_func/free_func
pair to be used to
do reallocations.
This function must be called before the context initialization
function
(rtInitContext
) because context
initialization requires low level memory management facilities be in
place in order to do its work.
Note that this function makes use of static global memory to hold
the function definitions. This type of memory is not available in all
run-time environments (most notably Symbian). In this case, an
alternative function is provided for setting the memory functions. This
function is
rtxInitContextExt
, which must be called
in place of the standard context initialization function
(rtInitContext
). In this case, there is a
bit more work required to initialize a context because the ASN.1
subcontext must be manually initialized. This is an example of the code
required to do this:
int stat = rtxInitContextExt (pctxt, malloc_func, realloc_func, free_func); if (0 == stat) { /* Add ASN.1 error codes to global table */ rtErrASN1Init (); /* Init ASN.1 info block */ stat = rtCtxtInitASN1Info (pctxt); }
Memory management can also be tuned by setting the default memory
heap block size. The way memory management works is that a large block of
memory is allocated up front on the first memory management call. This
block is then subdivided on subsequent calls until the memory is used up.
A new block is then started. The default value is 4K (4096) bytes. The
value can be set lower for space constrained systems and higher to
improve performance in systems that have sufficient memory resources. To
set the block size, the following run-time function should be used:
void rtxMemSetDefBlkSize (OSUINT32
blkSize);
This function must be called prior to context initialization.