Dynamic memory pool size

SGDK only sub forum

Moderator: Stef

Post Reply
Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Dynamic memory pool size

Post by Manveru » Thu Oct 27, 2016 12:00 pm

I am getting some strange behavior with the free memory return value when changing the STACK_SIZE value. I wonder what is the max size of the pool that guarantees that normal ram usage does not collide with the dynamic memory pool.

Thanks.
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Dynamic memory pool size

Post by Stef » Thu Oct 27, 2016 1:48 pm

What kind of strange behavior did you observed ?

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Re: Dynamic memory pool size

Post by Manveru » Thu Oct 27, 2016 2:29 pm

For example, i have an amount of free memory returned with MEM_get_free, and after when i change the code to allocate some memory statically instead of dynamically, i get a lower amout of free memory. It is like something overwrites some of the pool zone and get_free reads it like a non-free blocks. That's why i wonder how much of memory can be allocated with STACK_SIZE without interfering with the rest of the RAM usage.

When i change the STACK_SIZE constant i have to change also something in md.ld like the "_bend" value, or something else?
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Dynamic memory pool size

Post by Stef » Fri Oct 28, 2016 10:02 am

Manveru wrote:For example, i have an amount of free memory returned with MEM_get_free, and after when i change the code to allocate some memory statically instead of dynamically, i get a lower amount of free memory.
Of course, that is expected. When you statically allocate an object in C, it eats some part of the available heap memory so the dynamic memory manager has less memory to work with.

For instance if you do that (static allocation) :

Code: Select all

int myArray[1000];

int main()
{
  int free = MEM_getFree();
  ...
}
'free' will be lower than if you do that (no allocation) :

Code: Select all

int main()
{
  int free = MEM_getFree();
  ...
}
But normally you should have almost same free value when you do that (static allocation) :

Code: Select all

int myArray[1000];

int main()
{
  int free = MEM_getFree();
  ...
}
and that (dynamic allocation) :

Code: Select all

int* myArray;
  
int main()
{
  myArray = MEM_alloc(1000 * sizeof(int));
  int free = MEM_getFree();
  ...
}
In both case, 'free' value should be very close.

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Re: Dynamic memory pool size

Post by Manveru » Fri Oct 28, 2016 11:16 am

Oh i see. I understand better now how the memory works, bss and so. Thanks Stef.
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Dynamic memory pool size

Post by Stef » Fri Oct 28, 2016 2:42 pm

You're welcome !

Post Reply