How do you calculate the size of an array?

Photomofo

Active Member
Joined
Aug 20, 2012
Messages
259
Here's an array I'm using:

Dim Array (1 to 4, 1 to 400000, 1 to 12) as long

How big is this array? How big would it be as a double or string array?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Before I ask a question here I do 10 minutes to an hour of work looking for a solution. The key to finding a solution is asking the right question. Once I've asked a question here... in public... I find that I ask better questions and find my answer independently. It's funny how that works.

But then I'm also surprised nobody answered this question.
 
Upvote 0
Obviously, it is 4*400000*12 = 19,200,000 elements.

If you want know how much memory, multiply by the number of bytes for each type: Byte, Integer, Long, Single, Double, Decimal, Currency.

Enter "type long" or whatever into VBA help, and the help page tells you the number bytes.

For fixed-length strings like String*12, I presume (but I don't know) that VBA allocates just that amount of memory (e.g. 12 bytes).

Variable-length strings and Variant are a different animal altogether. AFAIK, MSFT does not document the overhead that it allocates for those types. You might do a google search to see if someone else has figured it out.

It would be nice if VBA had a sizeof() function. AFAIK, it does not.

We might use VarPtr arithmetic in order to infer the size of such types. But I would need to experiment with it myself (I'm not going to) in order to determine the reliability and the issues with such calculations.
 
Upvote 0

Forum statistics

Threads
1,214,845
Messages
6,121,902
Members
449,053
Latest member
Guy Boot

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top