Macros | |
#define | VLA(name, type, num) type name[num] |
#define | VLA_MAX(name, type, num, max) type name[num] |
#define | NON_POD_VLA(name, type, num) type name[num] |
#define | NON_POD_VLA_MAX(name, type, num, max) type name[num] |
The reason for defining these macros at all is that VLAs are not part of the C++ standard, and not available on all compilers. Regardless of the availability of VLAs, they should be avoided if possible since they run the risk of overrunning the stack if the length of the array is large, or if the function is called recursively. They can be used safely in cases where the size of the array is expected to be small, and the function will not be called recursively, and in these cases may avoid the overhead of allocation that might be incurred by the use of e.g. a vector.
define a variable-length array of non-POD data if supported by the compiler, or a fixed-length array of size max otherwise. This may have performance implications in the latter case if this forms part of a tight loop.
define a variable-length array if supported by the compiler, or a fixed-length array of size max otherwise. This may have performance implications in the latter case if this forms part of a tight loop.