Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on Array size 1

Status
Not open for further replies.

SukiStrider

Programmer
Jun 26, 2002
8
Hi,

I am trying to write a program that requires 65536 integer array elements (locations) I am using the Turbo 3.0 compiler on Windows 98 and every time I declare the array and try to compile the program I get an error:

declared Array size too large.

I have tried changing the memory model in the option screen of the IDE to huge (I have 512MB SDRAM) but I still have the problem.

I have alway thought that you can have unlimited array locations because it uses your computer's memory to hold the data, but I guess I am wrong.

Can anybody help me.
Thanks in advance.
 
In 16-bit Turbo C compiler(s) you have a limit for an array index value (32767) and 64K bytes (segment size) limit for dynamically allocated storage chunk (via malloc). Alas, you can't declare large arrays...
Try declare 2D array:
Code:
#define SXTYK (16*1024)
long* a[4];
a[0] = malloc(SXTYK); /* 1/4 total ints */
a[1] = malloc(SXTYK);
...
Now you can address the memory as
Code:
a[0][j] = ...;
/* example */
int n = SXTYK;
for (i = 0; i < 4; ++i)
for (j = 0; j < n; ++j)
   a[i][j] = (long)i*n + j;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top