Manuplating Stack Size

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Manuplating Stack Size

跳至解决方案
1,134 次查看
sandeepnaik
Contributor I

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.

标签 (1)
0 项奖励
回复
1 解答
821 次查看
bigmac
Specialist III

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

 

在原帖中查看解决方案

0 项奖励
回复
2 回复数
821 次查看
sandeepnaik
Contributor I

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!!!

0 项奖励
回复
822 次查看
bigmac
Specialist III

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

 

0 项奖励
回复