?
Printable View
?
65534 chars, I'm pretty sure.
I'll double check.
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
Yup, page 243 in VB for Dummies.
Yer fergettin Virtual memory.Quote:
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
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
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
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
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
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.
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:
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.Quote:
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.
Technically, thats wrong. But in practice, its right (mostly).Quote:
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.
The max-string length does depend on how much memory you have, but only because people never have 2GB of memory.
I found this quick, maybe it helps explain how strings in C are different from VB:
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).Quote:
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.
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)
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.
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.
Why would anyone want to use a 4TB string?!?!
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')
So that you can use the entire contents of the U.S. Libraray of Congress as an encryption key. Duh. :rolleyes:Quote:
Why would anyone want to use a 4TB string?!?!
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.
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.
Then you'd have a waaay larger key than file to be encrypted, that has not much use...Quote:
Originally posted by WorkHorse
So that you can use the entire contents of the U.S. Libraray of Congress as an encryption key. Duh. :rolleyes:
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.
That was a bit of sarcasm about concerns about string data type lengths. Of course you wouldn't use the entire...etc. etc. etc.
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!)Quote:
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.
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!
I know :)Quote:
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.
No, you'd have an out of paper message.
Ok, you win. :) :D ;)Quote:
Originally posted by Lord_Rat
No, you'd have an out of paper message.
Gotta think 3 Dimensionally :D
No you don't.Quote:
Originally posted by Lord_Rat
Gotta think 3 Dimensionally :D
(I think my brain's really starting to hurt)
(BTW, I have to go now, breakfast)
LOL! LMAO! That was dumb yet witty and unique! Good job Lord Rat! :DQuote:
Originally posted by Lord_Rat
No, you'd have an out of paper message.
Thanks!