|
-
Apr 5th, 2002, 02:06 PM
#1
Thread Starter
Frenzied Member
What is the maximum length of a string variable
-
Apr 5th, 2002, 02:08 PM
#2
65534 chars, I'm pretty sure.
I'll double check.
-
Apr 5th, 2002, 02:09 PM
#3
Hyperactive Member
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
-
Apr 5th, 2002, 02:09 PM
#4
Yup, page 243 in VB for Dummies.
-
Apr 5th, 2002, 02:10 PM
#5
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.
-
Apr 5th, 2002, 02:25 PM
#6
Hyperactive Member
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
-
Apr 5th, 2002, 02:30 PM
#7
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
-
Apr 5th, 2002, 02:34 PM
#8
Thread Starter
Frenzied Member
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
-
Apr 5th, 2002, 02:42 PM
#9
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
-
Apr 5th, 2002, 03:14 PM
#10
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.
-
Apr 6th, 2002, 11:18 PM
#11
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.
-
Apr 6th, 2002, 11:25 PM
#12
Frenzied Member
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.
-
Apr 6th, 2002, 11:35 PM
#13
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).
-
Apr 7th, 2002, 02:52 AM
#14
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)
-
Apr 7th, 2002, 03:05 AM
#15
Fanatic Member
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.
-
Apr 7th, 2002, 03:08 AM
#16
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.
-
Apr 7th, 2002, 03:08 AM
#17
Fanatic Member
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!
-
Apr 7th, 2002, 03:13 AM
#18
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')
-
Apr 7th, 2002, 03:13 AM
#19
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.
-
Apr 7th, 2002, 03:14 AM
#20
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.
-
Apr 7th, 2002, 03:19 AM
#21
Fanatic Member
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!
-
Apr 7th, 2002, 03:24 AM
#22
That was a bit of sarcasm about concerns about string data type lengths. Of course you wouldn't use the entire...etc. etc. etc.
-
Apr 7th, 2002, 03:25 AM
#23
Fanatic Member
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!
-
Apr 7th, 2002, 03:26 AM
#24
Fanatic Member
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!
-
Apr 7th, 2002, 03:27 AM
#25
No, you'd have an out of paper message.
-
Apr 7th, 2002, 03:28 AM
#26
Fanatic Member
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Apr 7th, 2002, 03:28 AM
#27
Gotta think 3 Dimensionally
-
Apr 7th, 2002, 03:30 AM
#28
Fanatic Member
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!
-
Apr 7th, 2002, 03:31 AM
#29
PowerPoster
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!
-
Apr 7th, 2002, 03:34 AM
#30
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|