Fixed length string vs Variable Length

Oorang

Well-known Member
Joined
Mar 4, 2005
Messages
2,071
If you have an string array that will not exceed 64 characters, but will generally be less than say 20 chars, would it be better to fix the string length at 64 or leave it a variable length string in terms of memory and speed? (The array is dynamic and the function could be called many times in an operation.)
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

tmcfadden

Board Regular
Joined
Aug 17, 2005
Messages
151
You're thinking of efficiency in VBA?!?! For shame!!!

Just kidding.

Unless you are doing thousands of allocations, you probably wouldn't see a difference either way. If you are doing thousands, I would imagine that a fixed length array that was 64 characters wide would be faster.

You would also want to create a large array at first ( guess at how many strings are needed ). If you are going to exceed that amount, allocate a bunch more locations and not just one.

Strings are tricky things, as is memory allocation. In general, it's always better to create a large chunk of memory one time than it is to create smaller chunks lots of times.

This would be a fairly easy thing to benchmark.

-Tim
 

Oorang

Well-known Member
Joined
Mar 4, 2005
Messages
2,071
True although, in a peice of irony I realized my little question was made irrelavant by the knowledge that vba.join will not work with fixed-length string-arrays because Join cannot coerce them into a variant(!) *sigh*. Let that be a lesson to me.
 

Forum statistics

Threads
1,136,704
Messages
5,677,297
Members
419,684
Latest member
BOB101

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
Top