12.14 Memory Models

The compiler supports several memory models. Command-line options are available for selecting the optimum memory model for your application, based on the specific device that you are using and the type of memory usage.

Table 12-1. Memory Model Command-Line Options
OptionMemory DefinitionDescription
-msmall-dataUp to 6 KB of data memory1.
The default is device dependent2.Permits use of PIC18 like instructions for accessing data memory.
-msmall-scalarUp to 6 KB of data memory1.
This is the default.Permits use of PIC18 like instructions for accessing scalars in data memory.
-mlarge-dataGreater than 6 KB of data 
memory1. The default is device dependent2.Uses indirection for data references.
-msmall-codeUp to 32 kWords of program memory. This is the default.Function pointers will not go through a jump table. Function calls use RCALL instruction.
-mlarge-codeGreater than 32 kWords of 
program memory.Function pointers might go through a jump table. Function calls use CALL instruction.
-mconst-in-dataConstants located in data 
memory.Values copied from program memory by startup code.
-mconst-in-codeConstants located in program memory. This is the default.Values are accessed via Program Space Visibility (PSV) data window.
-mconst-in-auxflashConstants in auxiliary Flash.Values are accessed via Program Space visibility window.
Note:
  1. For most devices 6K of RAM is the near data space, but for some devices it is 4K of RAM.
  2. For devices that have all of their data memory in the near space, the memory model is “small data” “small scalar” so that all memory will be allocated in the near space.
For all other devices the default memory model is “large data” “small scalar”. This will have the effect of allowing the tool chain to place aggregate objects, such as arrays and structure, into the far memory space. This can be over-ridden by explicitly selecting “small data” in the compiler options.

The command-line options apply globally to the modules being compiled. Individual variables and functions can be declared as near, far or in eds to better control the code generation. For information on setting individual variable or function attributes, see Variable Attributes and Function Specifiers.