Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

In an OCSDK application, memory is allocated in two different places:

  • Global variables - the "app vars" struct that you see in most programs are allocated by the compiler into unused RAM (that not allocated explicitly to tasks).  Any other globals are also allocated this way.
  • Task stacks - each task has a stack allocated based on the value from app_task_cfg.h passed to OSTaskCreateExt() - the value is in 32-bit words, so 256 = 1 KB. 
    • Variables in tasks or in functions called by tasks are allocated out of the tasks stack space

All memory allocation is static in the sense that it is set at compile time - there is no malloc() or free().  The keyword "static" in variable declaration refers to variable scope and lifetime, and does not affect where it is allocated.

The "app vars" are global in the scope of the user (p2) process - all tasks/functions in your OCSDK program can access them.  They are referred to as "variables local to this application" in the comments since their scope is limited to the user process, so they don't share a name space with the stack.  

Too much!

Allocating variables that exceed your program's share of RAM can have unexpected consequences.   Absurdly large allocations will fail to link - a 64K array will never be allowed.  Exceeding the 8K guidelines is trickier - it may work today, but fail on a later network library revision that uses more memory, or may work under certain conditions, then fail as the network activity increases.  If you do exceed the memory allocated to a task stack you may see faults, or unexpected asserts as memory get overwritten.  This can be very difficult to debug. 

Your guideline should be that globals + task stacks < 8K.  

 

  • No labels