Results 1 to 30 of 30

Thread: What is the maximum length of a string variable

  1. #1

    Thread Starter
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545

    What is the maximum length of a string variable

    ?

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    65534 chars, I'm pretty sure.

    I'll double check.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Omaha, NE
    Posts
    270
    According to a course book I have, the max length of a fixed-length string is up to 64K. The max length of a variable-length string (the normal kind) is 2GB. Boggles the mind doesn't it. That would be one honkin' machine to have 2+G's of memory.

    Nate

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Yup, page 243 in VB for Dummies.

  5. #5
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Originally posted by NateBrei
    According to a course book I have, the max length of a fixed-length string is up to 64K. The max length of a variable-length string (the normal kind) is 2GB. Boggles the mind doesn't it. That would be one honkin' machine to have 2+G's of memory.

    Nate
    Yer fergettin Virtual memory.

  6. #6
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Omaha, NE
    Posts
    270

    Wink

    Good point! I was. But still, you'd be lookin' at a fair gob of text. How many sets of the Encyclopedia Britannica would that be??? (Guys, that a retorical question. I don't expect someone to actually try to find that out.....

    Nate

  7. #7
    jim mcnamara
    Guest
    The reason for the dynamic string length is that it uses a long to remember the length of the string. VB creates what is called a string descriptor for each dynamic string. Looks like this
    ------------------------------------
    Descriptor type as 2bytes
    Address of first byte of string : as long
    length of the string: as long

    Fixed is like this:
    ---------------------------------------------
    Descriptor type as 2bytes
    Address of first byte of string : as long
    length of the string: as 2 byte integer
    Max length of string: AS 2 BYTE INTEGER



    Fixed len strings do this

  8. #8

    Thread Starter
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    Well 64 K cant be the limit cuz i just copied the contents of 100 K's worth of files into a string with no errors. Thanx for your response everyone

  9. #9
    jim mcnamara
    Guest
    A regular string is dynamic Dim t As String

    Use a fixed length string and see if you can get it to go beyond
    64K. You can't

  10. #10
    Red Rush-In
    Guest
    I don't understand the 2 gig limit for a variable length string. I thought the limit was based on the amount of memory you have.

    If VB stores strings the same way as C, the varible points to the address in memory where the string begins. Each consecutive address in memory is part of the string untill it reaches a Null (0 on most systems) value in memory.

  11. #11
    WorkHorse
    Guest
    I'm no expert on C, but I believe that variables in VB are different than C. My understanding is that VB creates its own sort of "psuedo-variables" that make them easier to deal with.

    As far as VB string lengths, from MS:

    String Data Type

    There are two kinds of strings: variable-length and fixed-length strings.

    A variable-length string can contain up to approximately 2 billion (2^31) characters.

    A fixed-length string can contain 1 to approximately 64K (2^16) characters.
    Per NateBrie's request I didn't calculate exactly how many Encyclopedia Britannicas would fit in a string, but the 2002 CD-ROM Deluxe edition has 56 million words, so figure a string could hold the text of about 4 complete encyclopedia.

  12. #12
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Originally posted by Red Rush-In
    I don't understand the 2 gig limit for a variable length string. I thought the limit was based on the amount of memory you have.
    Technically, thats wrong. But in practice, its right (mostly).

    The max-string length does depend on how much memory you have, but only because people never have 2GB of memory.
    You just proved that sig advertisements work.

  13. #13
    WorkHorse
    Guest
    I found this quick, maybe it helps explain how strings in C are different from VB:

    C++ strings: Introduction, String Length
    The C language does not have a native string type. Instead, programmers use null-character terminated arrays of characters (often referred to by char * which represents the beginning address of an array or buffer containing characters). While programmers have written effective code for years using these kinds of strings, even a beginner knows it's fundamentally different than other types in C. You need special functions to do what should be simple operations on strings, like assigning them values, comparing two strings, calculating their length, etc.

    C++ has had the potential for making this much cleaner by providing a class library to implement strings. A standard has been a long time in coming, but the international standards bodies are close to recognizing a standard C++ string class.

    Strings in C++ are objects.
    I'm stil confused, but maybe it shows that C strings aren't limted to a certain length, but VB strgings are (although (like a long) the maximum is huge enough that it would be very rare for anyone to actually encounter a problem with the limitation).

  14. #14
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    C++ strings have a 4 TB limit. (That's four tera-byte)

    That's becuase the stack cannot hold a memory/variable reference that would use a pointer greater than a 32 bit pointer.

    However, that 4 TB drops to:
    536870912 characters for Wide characters
    268435456 characters for Double Wide characters (Like Kanji and Chineese)

  15. #15
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    what if somebody writes a ram disk utility that needs to be larger than 2 gb?

    (yes, i know. who wouldn't write a ram disk utility in c++... and with that 4tb string length limit...)

    question, though... what happens in c++ if you attempt to address memory past the end of hardware memory AND past the end of virtual memory? does it just return nulls? or does it actually cause an error? i'm not a big c++ person, so i don't know this.

  16. #16
    WorkHorse
    Guest
    I'm guessing it doesn't return nulls because it would have no memory to store the null values, so it should give out of memory error.

  17. #17
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    Why would anyone want to use a 4TB string?!?!
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  18. #18
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    If you ref past memory, or in the Windows protection section of memory, you crash with an invalid page fault(memory is stored in 'pages')

  19. #19
    WorkHorse
    Guest
    Why would anyone want to use a 4TB string?!?!
    So that you can use the entire contents of the U.S. Libraray of Congress as an encryption key. Duh.

    I think it was just a question of exactly what the limits are. I've never heard of anyone having problems because of string overflows. It was just a question.

  20. #20
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    And, if you needed more than the 2TB, you could create a linked list and d-ref the linked list. That, though, is for another day.

  21. #21
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    Originally posted by WorkHorse
    So that you can use the entire contents of the U.S. Libraray of Congress as an encryption key. Duh.

    I think it was just a question of exactly what the limits are. I've never heard of anyone having problems because of string overflows. It was just a question.
    Then you'd have a waaay larger key than file to be encrypted, that has not much use...
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  22. #22
    WorkHorse
    Guest
    That was a bit of sarcasm about concerns about string data type lengths. Of course you wouldn't use the entire...etc. etc. etc.

  23. #23
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    Originally posted by Lord_Rat
    And, if you needed more than the 2TB, you could create a linked list and d-ref the linked list. That, though, is for another day.
    Oh sure, like if you want to put all the books ever published in a single string or display all the code of all the webpages ever made in one sting. (Ugh!)

    Fact: If you'd print out all the pages on the internet made so far, you'd have a layer of paper sheets of 3 miles high around the globe!
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  24. #24
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    Originally posted by WorkHorse
    That was a bit of sarcasm about concerns about string data type lengths. Of course you wouldn't use the entire...etc. etc. etc.
    I know
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  25. #25
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    No, you'd have an out of paper message.

  26. #26
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    Originally posted by Lord_Rat
    No, you'd have an out of paper message.
    Ok, you win.
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  27. #27
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Gotta think 3 Dimensionally

  28. #28
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    Originally posted by Lord_Rat
    Gotta think 3 Dimensionally
    No you don't.
    (I think my brain's really starting to hurt)

    (BTW, I have to go now, breakfast)
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  29. #29
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Originally posted by Lord_Rat
    No, you'd have an out of paper message.
    LOL! LMAO! That was dumb yet witty and unique! Good job Lord Rat!
    <removed by admin>

  30. #30
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width