Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

  • Global variables - the "app vars" struct that you see in most OCSDK sample programs are is allocated by the compiler into unused RAM (that not allocated explicitly to tasks).  Any other globals global declarations 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 declared in tasks or in functions called by tasks are allocated out of the tasks in the task's 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.  

Info

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!

OCSDK applications should limit their memory allocation so that the sum of global declarations and application-defined task stacks occupy less than 8K.

Allocating variables that exceed your program's share of RAM can have unexpected consequences.   Absurdly  Very large allocations will fail to link - if your program allocates a 64K array will never be allowed, the program will fail to link.  Exceeding the 8K guidelines is trickier - it may work today, but will fail on a later network library revision that uses more memory, or it 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 used by another part of the stack gets overwritten.  This  Memory corruption can be very difficult to debug. Your guideline should be that globals + task stacks < 8K.