Re:Regarding the RAM Monitor
Suresh,
The stack is an area of memory that the CPU uses to store variables and register contents temporarily during function calls and interrupts. The size of the stack is controlled by you and is determined by two factors - the number and size of local variables you use in your C functions and the maximum level of function call nesting you have in your application (since every time you call a function, register values are written onto the stack to save them and stack pointer is moved down to create some space for whatever local variables the function requires).
Practically speaking, I normally guess at the stack usage required then check to see how much is being used once the program is running and adjust as necessary. If I guess too low, I'll usually find that the program crashes horribly and looking at the stack pointer register (R13) will show that I've messed up and need to increase the size of the stack.
The heap is basically all the rest of RAM that is left over after program variables and stack have been taken out. Your program accesses it using C runtime functions such as malloc() and free(). These functions allow the program to keep track of the areas of memory which are in use and which are available.
Note that we don't use the C runtime heap in any of our example applications since we typically use static allocations (any memory blocks required are allocated using arrays in the C code rather than by making calls to a memory allocator). To enable malloc() and free(), you would probably need to modify the linker script used by your toolchain to tell it where the heap is to be placed in memory. There's a long discussion of this in this thread that you may find helpful.
Some of the third party code in StellarisWare does require a heap and, to support this, we also include the "bget" package in the third party section of the distribution. This is an open source memory manager that offers similar function to the C runtime malloc() and free() via functions bget() and brel(). It also offers the ability to query the amount of memory free in the heap using the bstats() function.
login or register to reply
|