User manual

334
mikoBasic PRO for PIC32
MikroElektronika
Memory Manager Library
This library provides routines for manipulating dynamic memory allocation. Dynamic memory allocation (also known
as heap-based memory allocation) is the allocation of memory storage for use in a program during the runtime of that
program.
Dynamically allocated memory exists until it is released. This is in contrast to static memory allocation, which has a
xed duration. It is said that an object so allocated has a dynamic lifetime.
The heap memory size can be congured in the Edit Project window. Also, user can override heap memory size in the
code, by setting the HEAP_SIZE constant.
Library Routines
- Heap_Init
- GetMem
- FreeMem
- MM_LargestFreeMemBlock
- MM_TotalFreeMemSize
Heap_Init
Prototype
sub procedure Heap_Init()
Description Sets Heap size.
Parameters None.
Returns Nothing.
Requires Nothing.
Example
const HEAP_SIZE = 3000 ‘ declare Heap size
Heap_Init() ‘ set Heap size
Notes None.
GetMem
Prototype
sub procedure GetMem(dim byref P as ^longword, dim WantedSize as word)
Description Fetches memory from the memory heap.
Parameters - WantedSize: pointer to the fetched memory
- WantedSize: size in bytes of the dynamic variable to allocate
Returns Returns a pointer to the fetched memory (of “WantedSize” bytes) in P if success; Otherwise 0 (no free
blocks of memory are large enough).
Requires Nothing.
Example
GetMem(ptr,20*sizeof(PBuffer)) ptr will point to a memory block where
PBuffer is allocated
Notes None.