int mold[639][479];
However, when I use that statement I get a message:
"Array to big for function main"
What do I need to do? I've tried different data types but none of them
have given me a different answer.
Thanks.
Hi,
Your problem is that DOS compilers only let you allocate memory
within the lower 640k. Your array is too big to be handled by the compiler.
Ways around this include XMS, EMS, ramdisks, putting your arrays in a file,
etc...
David
Several things. First of all, make sure you are compiling under the
huge memory model. This will allow you to have arrays greater than 64k. Yours
is twice that, since ints are two bytes each. Also, it isn't a bad idea to
make the variable far, and allocate it dynamically, like this:
int far * mold = new int far [639 * 479];
This should work.
1) I couldn't get any this to compile without error on Borland 3.1 or
MSVC 1.5 until I changed the far to __far and reduced the size of the
array. When you work it out 639 * 479 * 2 = 612162 bytes (assume int
is 2 bytes). Even with minimal code, this is going to be too big to
fit in the 640k limit. You would need to use one of the solutions
suggested by gcli...@ulkyvx.louisville.edu (EMM, XMS, etc).
2) The huge memory model uses far pointers by default. Do you need
to explicitly declare them?
3) far pointers won't work to access a memory block of more than 64k.
The segment is not incremented (decremented) when the offset crosses
a 64k boundary. You need to use huge pointers. So:
int __huge * mold = new int __huge [200 * 479L];
should work. Note the cast of one of the int constants to force the
math to be done as a long, instead of as an int.
4) If you declared it as :
int (__huge * mold)[479] = new int __huge [200][479];
/*This notation looks a little odd. Can anyone verify it?*/
you should be able to access the elements using the familiar 2 index
notation (ie, mold[3][23] = 12;) instead of using pointer math (ie,
mold[3*479 + 23] = 12).
--
John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
jat...@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
: int mold[639][479];
: However, when I use that statement I get a message:
: "Array to big for function main"
: What do I need to do? I've tried different data types but none of them
: have given me a different answer.
: Thanks.
I would try changing the memory model you are using to large, or
huge. If that doesn't work, try allocating the array with new or
malloc. Mostly likely , you will have to allocate an array of 'row's,
and then allocate another array for each row.
The problem is caused by the 16bit memory model used in Dos. This
model makes it difficult to have a variable bigger than 64k.
--
Don Garrett Louisiana Tech
dgar...@engr.latech.edu University
http://www.latech.edu/~dgarrett/
In article <4117br$9...@news.pacifier.com>,
int **mold,i;
mold = (int**)malloc(sizeof(int*)*640);
for (i=0;i<640;i++)
mold[i] = (int*) malloc(sizeof(int)*480);
viola, a large array.
- SKoT
SKoT McDonald Hons. Computer Science UWA
Email: sk...@cs.uwa.edu.au Phone: (09) 382 5518
Project: "Manufacturing Industrial: The Computer Generation
of Industrial Music via Rhythm Analysis"
--
SKoT McDonald Hons. Computer Science UWA
Email: sk...@cs.uwa.edu.au Phone: (09) 382 5518
Project: "Manufacturing Industrial: The Computer Generation
of Industrial Music via Rhythm Analysis"
Assuming your ints are 16 bits wide, you are trying to allocate 612,162
bytes of memory. Do you really expect to fit that into 640K of memory,
plus command.com, whatever else is loaded, and the rest of your program?
Perhaps you should be asking how to access extended or expanded memory.
Scott McKellar
Southwestern Bell Telephone
St. Louis, MO
(314) 235-3595 jm4...@multi.sbc.com
>In article <4117br$9...@news.pacifier.com>, <r...@pacifier.com> writes:
>> I'm using Turbo C++ 1.0. I'm writing a program where I need to store
>> information about every pixel on the screen , i.e:
>>
>> int mold[639][479];
>> "Array to big for function main"
>Assuming your ints are 16 bits wide, you are trying to allocate 612,162
>bytes of memory. Do you really expect to fit that into 640K of memory,
>plus command.com, whatever else is loaded, and the rest of your program?
>Perhaps you should be asking how to access extended or expanded memory.
Right on, Scott. Besides, the old BASIC standard would define 640
locations if you put in a 639, but in C, a [639] defines locations
0 through 638. So you need to put the full values, 640 and 480.
This would be 614,400 bytes of memory. You may have to use Disk,
or check out a DOS Extender which allows a variation of a malloc
call (of course you'd need the farmalloc or lmalloc variant).
You'd also need *mold to be far, so at the very least you could
define it as int far mold[640][480] but that would be subject to
limitations of the 640K limit as described earlier. I don't think
you can get there with the Turbo C++ 1.0 You probably need to
consider the Borland, Microsoft, or Watcom versions. B and W come
with DOS Extenders of different types.
In my applications, I create buffers in EMS or XMS. XMS is nice
because it is more likely to be available in current PC configurations,
and it has a copy utility built in. The only screwy restrictions are
that the amount allocated is in Kbytes, and the length of any data
transfer must be an even number of bytes. This means a minimum of
two, and odd transfers require two calls. You can transfer one byte
if you wanted to by reading then writing back a pair of bytes having
modified one of them. OK This is probably way more detail than
you need. The hassle is if you wanted fast access to the memory
for bit manipulations you will need the protected mode access to
get to over 600K memory block.
Regards,
Bryan G. Moore
bgm...@cts.com
v2.1
GE/CS/M/O d(++?) H- s-:- !g>g.25 p3 au+(*) a v(+++++)(---) w+
C++ UC+ L E- N+++ K- W(--) M(+)(-) V- po+ t-(++) 5 j R !G
b(+/-) B e+ h(--)(----) f- r+++9 n(----)(+++)
I suggest that you get djgpp from oak.oakland.edu. It is a 32bit compiler
for MSDOS and you will not run into the problems that you are now
encountering. The fact is that this array takes up 2*639*479 bytes (Actually
I think you mean 640x480) which is 612162 bytes. Since DOS only gives you
at most 640K to play with, you will not be able to do much no matter how you
wish to chop that array up, e.g.,
int *mold[640];
for (i = 0; i < 479; i++) mold[i] = (int *) malloc (sizeof (int) * 79);
Try djgpp. It is free and you will not regret it. See also the djgpp
newsgroup.
--John