Author Topic: Best practicies: data structures in heap or compile-time declarations?  (Read 8380 times)

Offline akorud

  • Newbie
  • *
  • Posts: 31
    • View Profile
Hi,
is there any practical difference (especially in our kind of software) between allocating data structures dynamically in heap and declaring them at compile-time?

regards,
Andriy Korud

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Hi Andriy

There is usually not a big difference - of course accessing then is either via a pointer (when on heap) or as struct when fixed (although one could in addition have a pointer to the fixed the struct).

Where heap based structs become useful is when the system is configurable. Eg. There are several task table configurations and a board configures itself to suit one of them (and can change the next time it configures itself). In this case, only the structs used by the specific configuration need to be constructed in heap rather than having to have all fixed for every possible configuration (even when not used) - this results in better memory utilisation.

Regards

Mark