User`s guide

16
K
A
DAK
KwikNet Overview
1.5 Memory Allocation Requirements
KwikNet must be able to dynamically allocate and free blocks of memory of varying sizes.
KwikNet supports three memory allocation strategies using standard C, a simple heap or
OS memory management services.
The KwikNet Library must be configured to select one of the three memory allocation
strategies. The strategy is defined by the parameters in your Network Parameter File.
The choices are made on the OS property page using the KwikNet Configuration Builder
(see Chapter 2.3).
When
KwikNet is used with the AMX Real-Time Multitasking Kernel, any of the
strategies can be used. The examples provided with the
KwikNet Porting Kit support
standard C, but can be easily modified to use the small heap or the memory allocation
services in your RT/OS.
Standard C Allocation
The first memory allocation strategy uses standard C library functions malloc() and
free() to allocate and free memory. This strategy is best used in single threaded
systems which are inherently thread-safe. If you use this strategy within a multitasking
system, you will have to use KwikNet's locking service to protect access to the library
functions unless your C runtime library provides thread-safe implementations of its
memory management functions.
KwikNet Simple Heap
The second memory allocation strategy offered by KwikNet is its simple heap, a region of
memory from which KwikNet carves memory as required. The memory region can be
assigned in three ways: 1) a single static array in memory; 2) a collection of one or more
blocks of memory acquired by KwikNet with calls to the C library's malloc() function; or
3) a collection of one or more blocks of memory acquired by KwikNet with calls to a user
provided memory acquisition function kn_msmemacquire().
If the KwikNet simple heap is dynamically constructed, its memory region will consist of
one or more memory blocks called pages. For 32-bit systems, there is no particular
advantage to splitting the memory region into multiple pages. However, for 16-bit
segmented systems you may very well have to use multiple pages in order to provide a
memory heap of more than 64K bytes. If the C library malloc() limits the amount of
memory which it will allocate, you will have to provide your own memory acquisition
function to provide the memory pages.