Memory

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 is allocated by the compiler into unused RAM (that not allocated explicitly to tasks).  Any other 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 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.  

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.  

Too much!

OCSDK applications should limit their memory allocation so that the sum of global declarations and application-defined task stacks occupy less than 16K with stack 1.3.2.1 or earlier, and 12 KB to "future proof" your application for later stack releases that have additional features.

Allocating variables that exceed your program's share of RAM can have unexpected consequences.  Very large allocations will fail to link - if your program allocates a 64K array, the program will fail to link.  Exceeding the 12K 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 used by another part of the stack gets overwritten.  Memory corruption can be very difficult to debug.