-
Programming and RAM
Hi all,
I am working to find an implementation strategy(in C for some application) for an embedded system with 24KB RAM.
I am trying to understand how the execution of code written in C is dependent on the size of RAM.
I understand that the whole source code will not reside in RAM.
Only part of data which the processor needs immediately will be loaded into RAM.
Which parts of the code actually reside in RAM?
or How much RAM is needed for a source code to execute?
In what way can I keep the contraint of 24KB RAM in mind, while I write my program in C?
Can you please tell how I should think about this?
I am actually confused.
Hope someone can make my mind clear about this.
Thank you
-
I am no expert on embedded systems, but could you elaborate what kind of code you are planning to load in RAM. Is it some application or some kernel module.? What OS you are you working on. ?
If the module is a kernel module, one way to reduce the code size is to include minimum header files in your code. Use already exported symbols (variables, functions) by the kernel or OS or share them among multiple soruce files. Your linker should take care of linking them in final build process.
Check the OS documentation for your emebedded system to find out the APIs.
-
The actual code size will be dependent on which opcodes/instructions the compiler generates when it turns your C code into machine language.
There is no real way to determine the size of your code until you compile it. As for arrays and such and assuming you know the data alignment being used, it is normally arraylength*sizeof(data_type_of_array).
-
> or How much RAM is needed for a source code to execute?
Depends how much you expect to get done.
A simple for loop for example probably occupies only a few bytes.
> I understand that the whole source code will not reside in RAM.
So some of the code is where else? Flash memory?
My initial thought is that the following fits into 24K
- the segment loader to load segments when they're needed
- some kind of function index to help the segment loader find the code you need next
- your run-time data
- the most common functions (so you're not continually swapping)
- some free space for swapping in segments on demand.