string variable

  • Thread starter Thread starter chriske911
  • Start date Start date
C

chriske911

I have a function that requires several string parameters
but these string parameters are all relatively short meaning they are
all just about 4 to 5 chars
can I somehow limit the length of a string variable so as not to waste
too much memory space with all these memory hungry variables?

it is just a informational question and not an operational issue
thought I saw this somewhere used before but could have been a
different programming language

thnx
 
chriske911 said:
I have a function that requires several string parameters
but these string parameters are all relatively short meaning they are
all just about 4 to 5 chars
can I somehow limit the length of a string variable so as not to waste
too much memory space with all these memory hungry variables?

it is just a informational question and not an operational issue
thought I saw this somewhere used before but could have been a
different programming language

It's possible to specify a fixed-length sting variable, but there's
seldom much need for it. What makes you think the string variables are
memory-hungry? The variables don't allocate memory for the maximum
possible length of a string, if they're not using it -- they allocate
memory for the number of characters they're using, plus a length
descriptor and some overhead. It would be a very unusual circumstance
where the memory used by a few string variables made a significant
difference in the memory usage of your application.
 
Don't worry about it. VBA takes care of the memory assignments for you, and
only uses the space it needs.

It is possible to create fixed-length strings, e.g.:
Dim str1 As String * 5
But space usage is not a good reason for doing so. Matching fixed-length
strings against variable length strings will probably give you bugs and
inefficiency rather than any benefit.
 
Allen Browne explained on 10/11/2006 :
Don't worry about it. VBA takes care of the memory assignments for you, and
only uses the space it needs.
It is possible to create fixed-length strings, e.g.:
Dim str1 As String * 5
But space usage is not a good reason for doing so. Matching fixed-length
strings against variable length strings will probably give you bugs and
inefficiency rather than any benefit.

thnx to both of you, I feel better knowing that I am not creating a
monster without knowing it

grtz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top