5.5 Table Resizing

It is best to maintain the size of tables on a running system. Table sizes are to be specified at startup in the boot configuration parameters. The system software and protocol tasks read this information and allocate the memory required for the tables. Dynamic resizing of tables, i.e., while the system is running, is not recommended. There are two reasons for this: reference modification and peak memory requirements.

Reference modification refers to a change in pointers during program execution. Pointer change is not a trivial task, especially in those cases where pointer values have been copied into other variables—a strong reason why dynamic resizing should be discouraged.

Consider a table sized 1000 bytes which needs to be resized to 2000 bytes. A logical approach is to simply resize the table by adding more bytes to the tail end of the table. This is usually not possible since the table and other data structures would have been pre-allocated in sequence from the heap, so there would be no free space to resize the table. Consequently, we need to allocate a new table sized 2000 bytes and copy the contents of the old table to this new table. The first table can be deallocated after the copy is done. However, all references to the earlier table through pointers now need to be changed to point to the new table. This is illustrated in Figure 5.6.

click to expand
Figure 5.6: Reference modification with table resizing.

The peak memory required to move data from the old to the new table is the second consideration. Consider the case in which there are only 1500 additional bytes available in the system when the resizing is needed. Since the new table needs only 1000 more bytes, there may appear to be no problem. However, the peak memory requirement during the copy operation is 3000 bytes (1000 for the old table and 2000 for the new table), so memory for the new table cannot be allocated, since we have not released the 1000 bytes for the old table. If there is a large number of tables to be resized, this approach soon becomes unmanageable.

In some MIBs, resizing of tables is permitted by setting a size variable with the SNMP manager. However, the MIB usually specifies that new values will take effect only after the next system reset (reboot), i.e., via modification of the boot parameters. Where resizing is required, this is the recommended approach.



Designing Embedded Communications Software
Designing Embedded Communications Software
ISBN: 157820125X
EAN: 2147483647
Year: 2003
Pages: 126
Authors: T. Sridhar

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net