Thanks for all the suggestions...
The idea of an external program seems most "secure" but it's not really "friendly"... and it could be simply done if using ASM only (no PBP) but the point was in using/extending PBP...
This "unfriendliness" is because of the fact that you should manually or with this program, alter an variable definition so to have that information available in runtime.
What I mean with this something like having a FLASH location with a dw _SYS_FREE_START_ (holding the value of first free ram location) so it could be used by the program for "dynamic allocations".
What I'm trying to accomplish is a "poor man" malloc() functionality (no, free(), no realloc()...) and for this I need the "free" info in runtime. So, with various programs and similar, you have to "manually" change that value in source and recompile to get the desired effect.
After some fiddling around and I think I found a "relatively good" solution:
declare an byte array which name is alphabetically last in order and which is bigger than any other defined byte array in your program. This kind of variable seems to be placed last in ram.
This method assumes:
- no direct allocations (with $address modifier) used in the program or at least you must be sure such addresses are before your other allocations
- no specific BANK n modifiers (other than BANKA/BANK0 or be sure to have enough other variables to use some bank "later" - example: if you use BANK 3 be sure to have enough variables to fill BANK0, 1, 2)
- enough free space to declare an byte array bigger than other used byte arrays (this seems reasonable if you need a malloc() anyway)
So, for example, if you declare
and put somewhere something similarCode:zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz var byte[1000]
you should be relatively sure the flash at address _RAM_FREE has the address of the first available RAM location.Code:@_RAM_FREE dw _zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
That can value could be put in a word var instead of flash for later use (as I mentioned - malloc())
So... if anyone needs a "dumb" malloc()...
This "malloc()" stuff can be easily used on 18F and on 16F "enhanced core" PICs... but mainly from ASM.
Regards,
MCulibrk




Bookmarks