Hi
I have the following code in cryptography. It is a function which accepts a "key" and "state" inputs and then encrypts state using key.
uint state[4]={0,1,2,3}; uint key[8]={1,2,3,4,5,6,7,8}; Encrypt(state,key);
When I increase size of the "state" variable, I expect to see RW-Data to grow. Because variables are located in RAM. But I see that code size and RO-Data increase instead.
Why ?!
I appreciate your help.
Regards
think about where those initialisation values come from ...
Thanks for quick answer.
Clarification: I do not extend initialization array, So this is fixed. I just add the array size.
Nevertheless, I do not expect neither increase in "CODE" size and nor change in "RW-Data".
If you have initialised data, it is put into CODE space and copied to RAM on startup. If you increase the size of the array, then the amount allocated in CODE will increase too.
This is NORMAL for an embedded system. You must learn to research how these things operate.
Thanks. I know how initialization data are copied from a non-volatile memory to RAM.
This is what I do not understand: I want to know how much RAM a crypto algorithm uses. But these two codes consume different CODE but the same RAM:
<par> uint state[4]={1}; </par> and <par> uint state[40000]={1}; </par>
This is not consistent with classic model of ROM/RAM memory usage.
f.n: I have used the entire array in my code. So none of it is trimmed by the compiler optimization.
uint state[4]={1};
and
uint state[40000]={1};
This is not consistent with classic model of ROM/RAM memory usage. NORMALLY, "state" variable located in RAM and its initialization values copied from ROM to RAM at the startup. Therefore, When I increase "state" variable size, I expect to see a growth in RAM.
I know how initialization data are copied from a non-volatile memory to RAM.
But you seem unaware of at least three things:
1) the reason why Keil calls this process "decompression" rather than just "copying".
2) the distinction between static and automatic variable lifetime, and its effect on initialization.
3) the fact that if you really want to know what's going on, you'll have to look at the compiled directly, not just at global consumption numbers.
Sorry, but it's blatantly obvious that you don't.
If you REALLY want to know, then you either have to actually interpret the answers given to you or you must carry out your own investigations.
I'm not wasting any more time with you.
First excuse me for bad English. This is the right sentence I wrote hastily:
I know THAT initialization data are copied from a non-volatile memory to RAM.
I did not really wanted to take your time.
BUT,
I wish that your first post was as short and informative as " Search this keyword" or "read that link" or "look at your compile directory" or at least your answer was like : "This is a very simple question, go and find the answer yourself. This forum is highly professional and I do not have time to answer simple questions!"
but instead it was to teach me that stop asking and "I must LEARN" to find answer by myself.
If an individual asks a question and I know the answer (but think that it is blatantly trivial and waste fo time) at least I give him a clue or even do not write anything for him, instead of teaching him that: he really DO NOT know anything and first must LEARN how to search for it.
My lesson: I will never come back here to ask anything.
Good luck.
Thank you Hans-Bernhard. This was helpful. and I did not know that.
I am preparing a report on memory usage of numerous algorithms.
So, I will try to find the maximum RAM usage during the execution of the program. This is what I actually have been looking for. And apparently is not obvious in the compiler global memory report.
Are you by any chance declaring these initialized variables within a function instead of globally? This would explain the behavior you are seeing very well.
local variables do not take up any more RAM than is already allocated for the stack even if your variable overruns the stack size.