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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,812
Members
449,048
Latest member
greyangel23

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