Array Size Considerations

2 pences from MSDN:

Array Size Considerations

There are several things
to keep in mind when dealing with the size of an array.

Dimension Length

The index of each
dimension is 0-based
, which means it
ranges from 0 through its upper bound. Therefore, the length of a given
dimension is greater by 1 than the declared upper bound for that dimension.

Length Limits

The length of every
dimension of an array is
limited
to the maximum value of the Integer
data type, which is (2 ^ 31) – 1. However, the total size of an
array is also
limited by the memory available on your system. If you attempt
to initialize an array that exceeds the amount of available RAM, the common
language runtime throws an OutOfMemoryException exception.

Size and Element Size

An array’s size is
independent of the data type of its elements.
The size always represents the total number of
elements
, not the number of
bytes that they consume in storage.

Memory Consumption

It is not safe to make any
assumptions regarding how an array is stored in memory
. Storage varies on platforms of different data
widths, so the same array can consume more memory on a 64-bit system than on a
32-bit system. Depending on system configuration when you initialize an array,
the common language runtime (CLR) can assign storage either to pack elements as
close together as possible, or to align them all on natural hardware
boundaries. Also, an array requires storage overhead for its control
information, and this overhead increases with each added dimension.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s