Dynamic Memory

With microcontrollers, dynamic memory allocation is often not used, or simply not practical. I found as the Pygmy GUI lib progressed, that dynamic memory allocation was going to be necessary. In Pygmy’s GUI lib, widgets such as buttons, labels and check boxes, are contained within forms. Forms inherit their basic properties from the global GUI structure and each widget inherits from it’s parent form. Forms are effectively pushed and popped from a stack to maintain drawing order. Disabled forms, or any individual widgets may be marked as visible or invisible to prevent wasted stack processing.

What does all this have to do with dynamic memory allocation? Well, to start with, the form stack would have to become static without dynamic allocation. This is problematic enough ( as I found when developing the sprites ), but becomes a nightmare when you consider that each form would then have to have a static stack of widgets as well. To prevent the cascading waste of memory that ensued, I added support for the standard GNU ARM malloc(), realloc() and free(). This involved new linker scripts, making the scripts more board dependent. Also, since planned Pygmy devices will include RAM that the standard lib will be unable to directly allocate, the functions must be “wrapped” to prevent conflicts.

Thus, sysAllocate(), sysReallocate() and sysFree() will mirror the functionality of malloc(), realloc() and free(). The dynamic support is currently only tested on the Nebula HP boards, but will soon be tested on the standard Nebulas as well. Additional enhancements related to the dynamic memory allocation slated for the near future will be a recoding to take advantage of dynamic allocation in the tasking, messaging, command and sprite interfaces.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: