Memory types used

Firmware/software/electronics/mechanics
Post Reply
Matt-
Beginner
Posts: 14
Joined: Thu May 08, 2014 2:22 am

Memory types used

Post by Matt- »

I am aware that C uses stack and heap memory, and on some embedded devices, the choice of memory used can be/is critical.

Does the Crazyflie use memory conservation strategies, to the degree that values are specifically stored on the stack or heap?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Memory types used

Post by arnaud »

Hi,

Crazyflie has 20K of RAM so yes we have to be a bit careful.

Crazyflie is running a real time operating system and has many tasks running in parallel. Each task mush have its own stack, so stack is pretty sensitive and should not be used too much.

Typically, we avoid as much as possible declaring structures as local variable. Either they are declared globally or locally as static (in both case this ends in the HEAP). But we have to be really careful to protect data on the heap: we have multiple tasks and only one task shall access a heap data at the same time.

There is two common case when using heap:
- The function is an init function or a specific function that will never be called from more than one task, then we can move some structure to heap (for init function it is worth trying to keep as much as possible in the stack to not use too much heap)
- The heap data are meant to be shared resource and Queue or Semaphores/Mutex are used
Matt-
Beginner
Posts: 14
Joined: Thu May 08, 2014 2:22 am

Re: Memory types used

Post by Matt- »

Hi, I've just hit a problem that I think is stack related. Just thought I'd say thanks for this post, it has helped with conceptualising the issue.

Of course it might be something else, but this is fitting what I'm seeing :)

Cheers!
Post Reply