Quote:
Originally Posted by interfect
Does anyone have an implementation of malloc? We really need some way to dynamically allocate memory, as we're running up against the 256 byte global per file limit.
|
There are a few different alternatives for getting around the 256 byte global per file limit.
If you need additional storage for variables, one option is to use the "#pragma" directive to explicitly put data into different memory "sections". Earlier this season, there was
a previous Chief Delphi thread which discussed this approach. Another posting describing this technique can be found in
this thread from 2006. Whether you use the "idata" or "udata" declarations depends upon whether or not the variables you are using are "initialized data" or "uninitialized data."
For more information on the use of the "#pragma" directive, you'll need to look at the MPLAB C18 Users manual. I don't know where to find the manual for version 2.4 of the compiler, but the MPLAB website does have
the manual for the newer 3.0 version.
In the above manual, see pages 20-26 for information on using the #pragma directive to be able to use more than one memory section for a given file.
If the storage you need is for "constant" data (for example, a large lookup table that is initialized to certain values, but then never changed) you can declare the "variables" (the ones that are constants that never change) with the "rom" qualifier so that these "variables" are actually stored in program memory. In that way, you can store much larger lookup tables, as long as the code never changes them dynamically. (The lookup tables would need to be changed by recompiling in that case.)
Hopefully one of these approaches will work for you!
__________________
Ken Streeter - Team 1519 - Mechanical Mayhem (Milford Area Youth Homeschoolers Enriching Minds)
2015 NE District Winners with 195 & 2067, 125 & 1786, 230 & 4908, and 95 & 1307
2013 World Finalists & Archimedes Division Winners with 33 & 469
2013 & 2012 North Carolina Regional Winners with teams 435 & 4828 and 1311 & 2642
2011, 2010, 2006 Granite State Regional Winners with teams 175 & 176, 1073 & 1058, and 1276 & 133
Team 1519 Video Gallery - including Chairman's Video, and the infamous "Speed Racer!"