66
Programming with TIDE
©2000-2008 Tibbo Technology Inc.
4.2.5.2
Memory Allocation for Procedures
Variable memory (RAM) allocation in TiOS is
. Memory is allocated
for variables at compile-time.
The compiler builds a "tree" reflecting procedure calls within your project. When
two different procedures never call each other, it is safe to allocate the same
memory space for the variables of each of them. They will never get mixed.
Let us say we have two event handlers in our project: on_event_1, which needs 7
bytes of memory, on_event_2, which needs 5 bytes of memory. They do not call
each other. In this case, the total memory required for our project will be 7 bytes
-- they will share the same memory space because only one will be executing at
any given time.
However, sometimes procedures call other procedures. This affects memory
allocation.
As seen above, the event handler on_event_1 calls procedure A, which in turn calls
procedure B. The memory required for each procedure is listed in brackets. Since
on_event_1, procedure A and procedure B call each other, they may not share the
same memory space. If procedure A keeps a variable in memory, then obviously
procedure B cannot use the same space in memory to store its own variables,
because procedure A may need its variable once control returns to it after
procedure B has completed. Thus, the total memory required for this tree is 11
bytes.
Now, let us say we also have on_event_2 in our project, which calls procedure C,
which in turn calls procedure D. This is a completely separate chain:
43