Memory Doesn’t Matter

A Variant data type takes up 16 bytes of memory and is structured as shown in Figure 5-1.

A common argument against Variants is that they take up more memory than do other data types. In place of an integer, which normally takes just 2 bytes of memory, a Variant of 16 bytes is taking eight times more space. The ratio is less, of course, for other underlying types, but the Variant always contains some wasted space.

The question is, as with the issue of performance discussed in the previous section, how significant is this? Again, I think not very. If your program has some extremely large arrays—say, tens of thousands of integers—an argument could be made to allow integers to be used. But they are the exception. All your normal variables in any given program are going to make no perceptible difference whether they are Variants or not.

I’m not saying that using Variants improves performance or memory. It doesn’t. What I’m saying is that the effect Variants have is not a big deal—at least, not a big enough deal to outweigh the reasons for using them.

Figure 5-1 The structure of a Variant