I wish to manipulate stack size for individual function.
My default stack size is 0x80 (128 bytes).
I have a function in which I dynamically allocate and dealloacte memory dynamically (about 120 bytes). I do-not wish to make it an global variable because it will unnecessary occupy RAM space rest of time when not used.
Any suggestion.
Can also someone explain me if implication of stack size.
If I declare to particular size of stack and don't use it completely then would I suffer internal fragmentation.
I am using MC9S08LG32 controller and CW 10.2
Thank You.
已解决! 转到解答。
Hello,
The dynamic memory allocation does not use the stack, but uses a separate heap. The default size of the heap is 2000 bytes, which exceeds your total RAM resources for the device you are using. It is possible to reduce the heap size, but this will require you to rebuild some library files.
https://community.freescale.com/message/19417#19417
I suggest that you try to avoid using malloc(). if the memory allocation can be handled as one or more local variable(s) within a function, increase the stack size by an appropriate amount.
However, if the variables require to be accessible by more than one function, they will need to be defined as static (or global), outside of any function. If the memory block has different types of usage at different times, this might be handled by defining a union.
Regards,
Mac
I am trying to use malloc and free function but getting error Out of Allocation Space Segment RAM at Address 0x131.
I have made provision that stack is down moving from last location of RAM.
I am of the belief that this error is due to stack size constraint. Is it true?
Any suggestions!!!
Hello,
The dynamic memory allocation does not use the stack, but uses a separate heap. The default size of the heap is 2000 bytes, which exceeds your total RAM resources for the device you are using. It is possible to reduce the heap size, but this will require you to rebuild some library files.
https://community.freescale.com/message/19417#19417
I suggest that you try to avoid using malloc(). if the memory allocation can be handled as one or more local variable(s) within a function, increase the stack size by an appropriate amount.
However, if the variables require to be accessible by more than one function, they will need to be defined as static (or global), outside of any function. If the memory block has different types of usage at different times, this might be handled by defining a union.
Regards,
Mac