User`s guide

KwikNet Overview
K
A
DAK
17
OS Memory Management
The third memory allocation strategy is to use the memory allocation services provided
by the operating system (RT/OS) with which KwikNet is being used. The operating
system may have its own private heap from which to allocate memory. However, some
multitasking operating systems, such as the AMX kernel, permit the use of a separate
memory region for privately allocating memory so that services such as those offered by
KwikNet can operate without interference caused by the memory demands of other,
unrelated tasks.
If the RT/OS requires its own memory region, it can be assigned in three ways: 1) a
single static array in memory; 2) a single block of memory acquired by KwikNet with a
call to the C library's malloc() function; or 3) a single block of memory acquired by
KwikNet with a call to a user provided memory acquisition function kn_msmemacquire().
Memory Acquisition Function
If you choose to do your own dynamic assignment of memory for a simple heap or for
use by your RT/OS, then you must provide a memory acquisition function
kn_msmemacquire() which KwikNet will call when it first starts. The prototype for this
function is as follows:
unsigned long kn_msmemacquire(char **mempp, unsigned long memsize);
The memory acquisition function must provide access to a fixed region of at least
memsize bytes of memory. The function must install a pointer to the memory region into
the pointer variable referenced as *mempp and return the value n, the actual size of the
region provided by the function.
If you choose to use the KwikNet simple heap with multiple pages of memory, KwikNet
will call your memory acquisition function kn_msmemacquire() repetitively to acquire
each of the memory pages.
When KwikNet shuts down it will call a function kn_msmemreturn() which you must
provide to dispose of the memory region, if necessary. The prototype for this function is
as follows:
int kn_msmemreturn(char *memp);
Parameter memp is a pointer to the region of memory previously acquired from your
kn_msmemacquire() function. If this function successfully handles the memory region
disposal, it must return the value 0. Otherwise, it must return a non-zero value.