Avoid using arrays as local variables or object fields

Aside from questions of stack size, arrays used as local variables or object fields must have their bounds determined at compile time. Using arrays with fixed bounds often signals that an arbitrary limit exists in your code. If that limit is exceeded, an exception or possible stack corruption results. If you use large arrays with fixed bounds, consider whether your code is general enough. If you are tempted to think, "Who would ever have more than 100 elements in this array?" please remember a similar query: "Who would ever want more than 64K (or 640K!) of memory in a personal computer?" On the other hand, if the size of your array is derived from the log of the number of elements you deal with (because, for example, it is a stack for a recursive algorithm) and it has 100 elements in it, you are probably safe.

For more information on storage management issues, see "Storage management philosophy" on page 85.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker