Hi, What you’re talking about is what malloc (memory allocate) in C does.
That’s intended for programs running under operating systems where other programs may be running,
and already consuming memory. So your program asks the system for a quantity of memory,
and a flag is returned if it was available.
I doubt it’s implemented in C for microcontrollers because the function would consume considerable
RAM and code space for many microcontrollers.
When you declare an array in PBP or RISC asm, all the compiler remembers is to reserve the next
memory spaces and mark the next variables in the locations following the array.
Code:
var byte array[20]
var byte value
In this case the variable “Value” will be permanently associated with RAM location 21,
and any time the array is used, the index is added to the array start location.
Code:
array[10] = 1
same as
(*array + 10) = 1
These numbers aren’t strictly true because PBP will put some of it’s own system variables before your array.
If there’s only one possible big array to deal with I don’t see a reason not to simply make it as large as you can afford.
If you don’t always use the maximum size of it, you can always mark the end with a normally unused character or sequence,
and search for that to find the current array size you’re using.
Bookmarks