Microchip Technology SW006022-1N Data Sheet

Page of 338
Memory Allocation and Access
 2012 Microchip Technology Inc.
DS52071B-page 141
7.10.3
Accessing EEDATA Using Managed Access
On most device the EE Data space is part of the program address space. Therefore 
EEData can be accessed automatically using one of the managed access qualifiers 
_ _psv__
 or __eds__.
EXAMPLE 7-3: 
EXAMPLE 6-2 USING MANAGED PSV ACCESS
#include <p30Fxxxx.h>
__eds__ char user_data[] __attribute__((space(eedata))) = { /* values 
*/ };
int main(void) {
  int value;
  value = user_data[0];
  if (value) ; /* do something */
}
7.10.4
Additional Sources of Information
The device Family Reference Manuals have an excellent discussion on using the Flash 
program memory and EE data memory provided. These manuals also have information 
on run-time programming of both program memory and EE data memory.
There are many library routines provided with the compiler. See the 16-Bit Language 
Tools Libraries
 (DS51456) manual for more information.
7.11
DYNAMIC MEMORY ALLOCATION
The C run-time heap is an uninitialized area of data memory that is used for dynamic 
memory allocation using the standard C library dynamic memory management 
functions, calloc, malloc and realloc. If you do not use any of these functions, 
then you do not need to allocate a heap. By default, a heap is not created.
If you do want to use dynamic memory allocation, either directly, by calling one of the 
memory allocation functions, or indirectly, by using a standard C library input/output 
function, then a heap must be created. A heap is created by specifying its size on the 
linker command line, using the --heap linker command-line option. An example of 
allocating a heap of 512 bytes using the command line is:
xc16-gcc foo.c -Wl,--heap=512
The linker allocates the heap immediately below the stack.
You can use a standard C library input/output function to create open files (fopen). If 
you open files, then the heap size must include 40 bytes for each file that is simultane-
ously open. If there is insufficient heap memory, then the open function will return an 
error indicator. For each file that should be buffered, 4 bytes of heap space is required. 
If there is insufficient heap memory for the buffer, then the file will be opened in unbuf-
fered mode. The default buffer can be modified with setvbnft.