User manual
170
mikoC PRO for dsPIC
MikroElektronika
Memory Type Qualiers
In addition to the standard storage qualiers(const, volatile) the compiler introduces storage qualiers of near 
and far.
Near Memory Qualier
  1. Data Memory Objects 
   The qualier near is used to denote that a variable is allocated in near data space (the rst 8 kB of Data 
   memory). Such variables can sometimes be accessed more efciently than variables not allocated (or not 
   known to be allocated) in near data space. 
   If variables are allocated in the near data section, the compiler is often able to generate better (more 
   compact) code than if the variables are not allocated in the near data section.
  2. Program Memory Objects 
   The qualier near is used to denote that a constant is allocated in the default program memory page 
   (32kB segment of program memory). Default program memory page is the one with most free space and 
   is set by the compiler by analyzing program memory pages. 
   This qualier is set as default by the compiler, if no other qualier is used.
Far Memory Qualier
  1 Data Memory Objects 
   The qualier far is used to denote that a variable will not be in near data space (i.e. the variable can be 
   located anywhere in data memory). This qualier is set as default by the compiler, if no other qualier is 
   used.
  2. Program Memory Objects 
   The qualier far is used to denote that a constant can be allocated anywhere in the program memory, in 
   the page pointed to by PSVPAG register.
Location of object based on memory qualiers:
Qualier/Memory Data Memory Program Memory 
near
First 8 kB of RAM In default page
far
Anywhere in RAM In page pointed to PSVPAG register
Example: 
char i;  // far memory qualier is set, variable i can allocated somewhere in data memory
char near j;  // near memory qualier is set, variable j will be allocated in the rst 8kB of data memory
const int k = 10; // near memory qualier is set, constant k will be allocated in the default memory page
Related topics: dsPIC Memory Organization, dsPIC Memory Type Speciers










