nigh
Newbie level 6
- Joined
- Aug 24, 2011
- Messages
- 13
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,379
Hi,
I am a beginner level developer and until now I have been working on PIC18 & PIC16 using MikroC compiler. But now I am working on a project with LPC2138, an ARM7 based MCU from NXP, using Keil uVision.
The project includes GSM module interfacing, EEPROM, SD card, different digital (with I2C and SPI interface) and analog sensors etc. This may later include USB and Ethernet interfacing too (for which I intend to shift to LPC2378).
Well ... In case of MikroC, the compiler allocates all required memory ONLY at compile-time (a negative aspect of which is that the functions are non-reentrant) so I never had to worry about the concepts like dynamic memory allocation and heap etc.
Now with Keil, I started developing without giving much thought to memory management. Once I created an array of 4000 elements inside a function (local variable) and after compilation there was no significant change in used RAM space. This made me start wondering about compiler's memory management.
According to my current knowledge about PC high-level programming:
1. local variables: values are stored on stack and references are stored on heap
2. dynamically allocated variables (using malloc etc) are stored on heap
if above two points are correct and these concepts apply to MCU's as well, then my array would be created on stack and if there's not enough stack, there would be stack-overflow. Am I correct?
I used this syntax to create my array:
my second question is:
Who Pushes and Pops the data to and from stack as there is no OS in my case. Does compiler include some house-keeping code during compilation/linking?
P.S. I would also like to discuss the concepts like function reentrancy and dynamic memory allocation in some detail but first let's clear my concepts about above two questions.
P.P.S. if you think that this question is possible duplicate, please overlook my laziness although I did try (a bit) to find my answers through google. please provide me some pointers where i could have learned these things.
Thanks in advance. I'd really appreciate your response.
I am a beginner level developer and until now I have been working on PIC18 & PIC16 using MikroC compiler. But now I am working on a project with LPC2138, an ARM7 based MCU from NXP, using Keil uVision.
The project includes GSM module interfacing, EEPROM, SD card, different digital (with I2C and SPI interface) and analog sensors etc. This may later include USB and Ethernet interfacing too (for which I intend to shift to LPC2378).
Well ... In case of MikroC, the compiler allocates all required memory ONLY at compile-time (a negative aspect of which is that the functions are non-reentrant) so I never had to worry about the concepts like dynamic memory allocation and heap etc.
Now with Keil, I started developing without giving much thought to memory management. Once I created an array of 4000 elements inside a function (local variable) and after compilation there was no significant change in used RAM space. This made me start wondering about compiler's memory management.
According to my current knowledge about PC high-level programming:
1. local variables: values are stored on stack and references are stored on heap
2. dynamically allocated variables (using malloc etc) are stored on heap
if above two points are correct and these concepts apply to MCU's as well, then my array would be created on stack and if there's not enough stack, there would be stack-overflow. Am I correct?
I used this syntax to create my array:
Code C - [expand] 1 char arr[4000] = "";
my second question is:
Who Pushes and Pops the data to and from stack as there is no OS in my case. Does compiler include some house-keeping code during compilation/linking?
P.S. I would also like to discuss the concepts like function reentrancy and dynamic memory allocation in some detail but first let's clear my concepts about above two questions.
P.P.S. if you think that this question is possible duplicate, please overlook my laziness although I did try (a bit) to find my answers through google. please provide me some pointers where i could have learned these things.
Thanks in advance. I'd really appreciate your response.