Is there a practical limit to how many characters in a string variable?

E

Ed

I've got the Word 2000 Developer's Handbook. It says a string
variable can hold up to 2 billion characters. Looking at a document
I've got now, that translates into about 4400 pages like this one.

But is that a _practical_ limit? Will I crash and burn if I begin to
approach a certain percentage of that size? Or can I take it right up
to 1.99 billion with no issues?

Ed
 
K

Karl E. Peterson

Ed said:
I've got the Word 2000 Developer's Handbook. It says a string
variable can hold up to 2 billion characters. Looking at a document
I've got now, that translates into about 4400 pages like this one.

But is that a _practical_ limit? Will I crash and burn if I begin to
approach a certain percentage of that size? Or can I take it right up
to 1.99 billion with no issues?

You'll crash and burn. <g> In 32-bit Windows, each *process* is allocated 2Gb of
address space. Total. VB(A) String's contain two bytes per character. The math
isn't looking favorable already, eh? Now consider that Word is already using up a
sizable, though not hefty, chunk of that initial allocation. And that the other
variables in your code are also competing for their own share. And, well, the math
is definitely going against ever even coming close to this theoretical (but,
obviously now, erroneous) upper limit.

Practically, you *might* get by with the occassional string that approaches half
that size. I'd rarely consider that truly practical, though, and strive to keep
them 1/8 to 1/16 that large, at most. And remember, they're all competing for their
share of the total. It wouldn't take too many 250M char strings to blow the joint.

Oh, and if you *do* start making really, really huge strings, you'll want to be
*really* careful how you build them. Nothing's more expensive than concatenation.
 
E

Ed

Thanks, Karl. I wouldn't be using concatenation. It's a web page of
text that I need to copy and set into a Word doc. We keep interim
reports on a web site, and I'm trying to automate getting all of them
into a Word doc, where I already have code that parses the "master"
doc into the individual reports.

But if I get a call for a major project that's run for a few years, it
could have several thousand reports. So far my automation (through a
Word macro) lets memanipulate the buttons and such on the page to put
all of the reports for any project into one single continuous web
page. Right now I'm using
strMsg = docIE.Body.InnerText
but I'm afraid that might not hold up for one of the bigger projects.

Any thoughts on how to avoid disaster on this one?

Ed
 
K

Karl E. Peterson

Ed said:
all of the reports for any project into one single continuous web
page. Right now I'm using
strMsg = docIE.Body.InnerText
but I'm afraid that might not hold up for one of the bigger projects.

Any thoughts on how to avoid disaster on this one?

"Divide and conquer." The strategy is ancient, but very well proven.

Honestly, it's hard for me to imagine how big a document this might be. Something
*no one* would want to read in a web page, no doubt. I mean, you're approaching
~100x longer than the longest novel ever written! :)

Amazon.com: "Read the Ten Longest Novels Ever Written"
http://www.amazon.com/gp/richpub/syltguides/fullview/22F3SA74XBA5Y

If you seriously think you might actually go over 10 million chars in a report, it's
probably time to really wonder what's the real point of it all, eh? I'm not sure
any 32-bit app is going to freely be willing to display such a piece of work.
 
E

Ed

Thanks for all your help, Karl. I think I lost you a bit on what I'm
doing, but that didn't affect the essence of your advice. I think I
need to restructure my code so the web page that I'm copying simply
doesn't get that big. Then repeat as needed until I get everything.
The chunks can still be quite big, but maybe not the whole thing.
Yeah, I can make that work!

Cheers!
Ed
 
K

Karl E. Peterson

Ed said:
Thanks for all your help, Karl. I think I lost you a bit on what I'm
doing, but that didn't affect the essence of your advice. I think I
need to restructure my code so the web page that I'm copying simply
doesn't get that big. Then repeat as needed until I get everything.
The chunks can still be quite big, but maybe not the whole thing.
Yeah, I can make that work!

<g>

All I was really saying was, it's hard to imagine a webpage *so* big you'd blow even
a 0.1-billion character buffer. Anything that big shouldn't ever be treated as a
String, IMO.

Good luck...
 

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

Top