By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,918 Members | 1,520 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,918 IT Pros & Developers. It's quick & easy.

huge 2-D array

P: n/a
is anyone know how to implement a huge 2-D array?
such as ' unsigned char a[1500][1500]; '
I compile and run it in VC 6.0, but it show me an error....
thank you guys

Apr 16 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
lu**********@gmail.com wrote:
is anyone know how to implement a huge 2-D array?
such as ' unsigned char a[1500][1500]; '
I compile and run it in VC 6.0, but it show me an error....
thank you guys


No errors here (gcc). Maybe there is an error somewhere else?
Please post the code that has problems.
Apr 16 '06 #2

P: n/a
For example:

void main(void){
unsigned char a[1500][1500];
}

I can compile it without error, but when I run it, it show me an
error.......
Is that array too big?

Apr 16 '06 #3

P: n/a
In article <e1**********@volcano1.grnet.gr>,
Giannis Papadopoulos <ip******@inf.uth.gr> wrote:
lu**********@gmail.com wrote:
is anyone know how to implement a huge 2-D array?
such as ' unsigned char a[1500][1500]; '
I compile and run it in VC 6.0, but it show me an error....
No errors here (gcc). Maybe there is an error somewhere else?
Please post the code that has problems.


The problem is probably just that it is a big array. C implementations cannot
necessarily support huge arrays; VC 6.0 has been noted a few times before
as restricting the array size.

I'm going to guess further that the OP is trying to declare that array
as an 'auto' variable (i.e., a local variable in a routine.) The array
occupies about 2 1/4 megabytes, which is larger than some implementations
allow for local variables. Declaring the variable to be 'static' might
clear up the problem for the OP, if the routine is not called recursively.
If not, then the OP will likely need to malloc() the space.

--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
Apr 16 '06 #4

P: n/a
lu**********@gmail.com wrote:
is anyone know how to implement a huge 2-D array?
such as ' unsigned char a[1500][1500]; '
I compile and run it in VC 6.0, but it show me an error....
thank you guys

Consider malloc(). 2,250,000 bytes is rather much for an array
definition. See the C FAQ for more about this.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Apr 16 '06 #5

P: n/a
thank you~!
I declared the variable into 'static', and there is no error now.

Apr 16 '06 #6

P: n/a
<lu**********@gmail.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
For example:

void main(void){
unsigned char a[1500][1500];
}

I can compile it without error, but when I run it, it show me an
error.......
Is that array too big?


You should include context in your replies or people cannot tell what you
are talking about. Furthermore, that should have been:

int main(void)
{
unsigned char a[1500][1500];
return 0;
}

You can try to malloc() the same amount of memory and see if that fails too.
You can try the following:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
unsigned char *p;
if ((p=malloc(1500*1500))!=NULL)
{
printf("Success!\n");
free(p);
}
else
{
printf("Failure!\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

or something with the same effect as the above.
Apr 16 '06 #7

P: n/a
lu**********@gmail.com wrote:
thank you~!
I declared the variable into 'static', and there is no error now.


Please read the information below.

Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Apr 16 '06 #8

P: n/a
lu**********@gmail.com wrote:
is anyone know how to implement a huge 2-D array?
such as ' unsigned char a[1500][1500]; '
I compile and run it in VC 6.0, but it show me an error....
thank you guys

Sometimes it helps to make it static char[1500][1500],
on a number of compilers your type will be on the stack,
while the static one will be in general memory space.
(I am sure someone will object/declare it of topic.)
Apr 17 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.