|
-
Oct 20th, 2002, 06:45 AM
#1
Thread Starter
Member
Large Char arrays
Is there any way I can declare an array of char that is about 4,000,000 elements long? When I try to do so, the program crashes.
-
Oct 20th, 2002, 06:54 AM
#2
Monday Morning Lunatic
OS? Compiler?
For Windows, you can't have more than a megabyte in stack data, so you'll need to do something like:
Code:
char *ptr = new char[4000000];
// ...
delete[] ptr;
This will put it into heap memory, which has more space.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 20th, 2002, 07:03 AM
#3
At 4 MB, if you don't care about portability, you'll be best of using VirtualAlloc, which is designed to allocate very large amounts of memory.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 21st, 2002, 02:50 PM
#4
Frenzied Member
Anytime you use arrays of that size, you get problems. Almost without exception you are better off using an external agent (like a database) to handle your data. The database developers have found most of the gotchas and know how to get around them. You won't.
CB is right - if you call malloc, your system may thrash for 20 seconds even if the memory allocation completes successfully.
This only only one of dozens of problems you'll encounter.
You have to use long int (int in MSVC++) to reference elements of an array that large. And so on.
-
Oct 22nd, 2002, 03:19 AM
#5
New Member
Urgh, I'll stick with malloc for now, it seems to work well enough. Thank y'all
-
Oct 22nd, 2002, 11:43 AM
#6
VirtualAlloc is guaranteed to scare any casual onlooker off.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
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
|