VB6 - Is there any performance benefit gained by using fixed-width strings in VB6?

No, there is no performance benefit.

BUT even if there were, unless you were calling many (say millions) times in a loop, any performance benefit would be negligible.

Also, fixed-length strings occupy more memory than variable-length ones if you are not using the entire length (unless very short fixed length strings).

As always, you should carefully benchmark before making the code harder to maintain.

Fixed length strings were usually seen when interacting with some COM API's, or when modelling to domain constraints (such as the example you gave of a SSN)


The only time in VB6 or earlier that I had to use fixed length strings was with working with API calls. Not passing a fixed length string would cause unexplained errors at times when the length was longer than expected, and even sometimes when shorter than expected.

If you are going through and planning to change that in the application make sure there is no passing of the strings to an API or external DLL, and that the program does not require fixed length fields to be output, such as with many AS/400 import programs.

I personally never got to see a performance difference as I was running loops of 300k+ records, but had no choice but to provide and work with fixed lengths when I did. However VB likes to use undefined lengths by default so I would imagine the performance would be lower for fixed length.

Try writing a test app to perform a basic concatenation of two strings, and have it loop over the function like 50k times. Time the difference between the two of having one undefined length and the other fixed.

Tags:

String

Vb6