Maximum size of an array | | |
What is the maximum size of an array? I tried to edit an extremely large
array for a magic square, for example, array[3001][3001], and when I ran the
program, it would not display the array. I changed the array to 105 by 105
and it worked fine. Does anybody know what the problem is and how I could
possibly get around it? | | | | re: Maximum size of an array
"eggie2486" <eggy2486@twcny.rr.com> wrote...[color=blue]
> What is the maximum size of an array? I tried to edit an extremely large
> array for a magic square, for example, array[3001][3001], and when I ran[/color]
the[color=blue]
> program, it would not display the array. I changed the array to 105 by[/color]
105[color=blue]
> and it worked fine. Does anybody know what the problem is and how I could
> possibly get around it?[/color]
The problem can be simply a limited amount of storage available to your
program during its execution. That's beyond the language specification,
you need to consult the manual for programming your OS and/or the manual
for your compiler.
Often different sizes of arrays can be had for static, automatic, and
dynamic arrays. Since you didn't indicate what kind of an array you had,
I assume it was automatic. Look for a compiler switch that allows you
to control the "stack size" (which is not related to std::stack template).
But please don't ask us, particular compiler switches are off-topic here.
Victor | | | | re: Maximum size of an array
It depends on your pc's memory size.
for example,if your declared an array: int array[3001][3001]
it needs 32bit*3001*3001=288M memory space.
in such way,you can calculate the Maximum size of array you can you use
according
to your array type and memory size.
"eggie2486" <eggy2486@twcny.rr.com> дÈëÓʼþ
news:hzZhc.77165$M3.977@twister.nyroc.rr.com...[color=blue]
> What is the maximum size of an array? I tried to edit an extremely large
> array for a magic square, for example, array[3001][3001], and when I ran[/color]
the[color=blue]
> program, it would not display the array. I changed the array to 105 by[/color]
105[color=blue]
> and it worked fine. Does anybody know what the problem is and how I could
> possibly get around it?
>
>[/color] | | | | re: Maximum size of an array
eggie2486 wrote:[color=blue]
> What is the maximum size of an array? I tried to edit an extremely large
> array for a magic square, for example, array[3001][3001], and when I ran the
> program, it would not display the array. I changed the array to 105 by 105
> and it worked fine. Does anybody know what the problem is and how I could
> possibly get around it?
>
>[/color]
I think it is related to the size of the stack allocated by the
compiler/linker. I think 4KB might be the standard stack size for a x86.
I sure you will find some switch for the compiler/linker you are using
to change the default stack size. | | | | re: Maximum size of an array
.. wrote:
[color=blue]
> eggie2486 wrote:
>[color=green]
>> What is the maximum size of an array? I tried to edit an extremely large
>> array for a magic square, for example, array[3001][3001], and when I
>> ran the
>> program, it would not display the array. I changed the array to 105
>> by 105
>> and it worked fine. Does anybody know what the problem is and how I
>> could
>> possibly get around it?
>>
>>[/color]
>
> I think it is related to the size of the stack allocated by the
> compiler/linker. I think 4KB might be the standard stack size for a x86.
> I sure you will find some switch for the compiler/linker you are using
> to change the default stack size.[/color]
No, has nothing to do with the stack area, but the area where the
array is allocated from. The OP did not say whether the array was
created from dynamic memory (a.k.a the heap), block or local memory
(a.k.a. the stack), or where automatic variables are declared.
The amount of memory available depends on:
1. The total memory on the platform.
2. The amount of memory allocated to the program.
3. The compiler's settings.
--
Thomas Matthews
C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html
Other sites: http://www.josuttis.com -- C++ STL Library book | | | | re: Maximum size of an array
Eric Lee wrote:[color=blue]
> It depends on your pc's memory size.
> for example,if your declared an array: int array[3001][3001]
> it needs 32bit*3001*3001=288M memory space.[/color]
32bit*3001*3001 is not 288M, it's approx 36M.
Plus sizeof(int) is not necessarily 32 bits.
- J. | | | | re: Maximum size of an array
"Jacek Dziedzic" <jacek__NOSPAM__@janowo.net> wrote...[color=blue]
> Eric Lee wrote:[color=green]
> > It depends on your pc's memory size.
> > for example,if your declared an array: int array[3001][3001]
> > it needs 32bit*3001*3001=288M memory space.[/color]
>
> 32bit*3001*3001 is not 288M, it's approx 36M.
>
> Plus sizeof(int) is not necessarily 32 bits.[/color]
That's all true. But if sizeof(int)*CHAR_BIT is not 32 (but
smaller, supposedly), then sizeof(int*) is smaller too, probably.
Then for such system it's rather difficult to organise addressing
in an array whose size is greater than 2^(sizeof(int*)*CHAR_BIT).
For example, on 16-bit systems it was a chore to have an array
larger than 64K in total bytes, no matter how much memory your
computer had installed.
Victor | | | | re: Maximum size of an array
Victor Bazarov wrote:
[color=blue]
> That's all true. But if sizeof(int)*CHAR_BIT is not 32 (but
> smaller, supposedly), then sizeof(int*) is smaller too, probably.[/color]
Why would you think that? There's no relationship between the size of
int and the size of pointers despite all the code out there (much of it
promoted as "portable") that assumes sizeof(int)==sizeof(whatever*). | | | | re: Maximum size of an array
"Bill Seurer" <seurer@us.ibm.com> wrote...[color=blue]
> Victor Bazarov wrote:
>[color=green]
> > That's all true. But if sizeof(int)*CHAR_BIT is not 32 (but
> > smaller, supposedly), then sizeof(int*) is smaller too, probably.[/color]
>
> Why would you think that?[/color]
Because I worked on more than one platform where that was true.
I also worked on a platform where it wasn't true, but you had to
take special steps.
[color=blue]
> There's no relationship between the size of
> int and the size of pointers despite all the code out there (much of it
> promoted as "portable") that assumes sizeof(int)==sizeof(whatever*).[/color]
I am not aware of any such code, but you must be right, you state
all that with such conviction... Besides, I did say "probably",
didn't I? | | | | re: Maximum size of an array
On Fri, 23 Apr 2004 00:37:33 GMT, "eggie2486" <eggy2486@twcny.rr.com>
wrote:
[color=blue]
>What is the maximum size of an array? I tried to edit an extremely large
>array for a magic square, for example, array[3001][3001], and when I ran the
>program, it would not display the array. I changed the array to 105 by 105
>and it worked fine. Does anybody know what the problem is and how I could
>possibly get around it?[/color]
Allocate from the heap:
typedef int (*array_t)[3001];
array_t array = new array_t[3001];
or, more likely,
class MagicSquare
{
//...
private:
int m_squares[3001][3001];
};
MagicSquare* magicSquare = new MagicSquare(); //allocate from heap
Generally, when allocating large amounts of memory, use dynamic
storage. Automatic storage is generally much more limited than dynamic
storage.
Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html | | | | re: Maximum size of an array
On Wed, 28 Apr 2004 09:44:59 +0100, tom_usenet
<tom_usenet@hotmail.com> wrote:
[color=blue]
>On Fri, 23 Apr 2004 00:37:33 GMT, "eggie2486" <eggy2486@twcny.rr.com>
>wrote:
>[color=green]
>>What is the maximum size of an array? I tried to edit an extremely large
>>array for a magic square, for example, array[3001][3001], and when I ran the
>>program, it would not display the array. I changed the array to 105 by 105
>>and it worked fine. Does anybody know what the problem is and how I could
>>possibly get around it?[/color]
>
>Allocate from the heap:
>
>typedef int (*array_t)[3001];
>array_t array = new array_t[3001];[/color]
I messaged that up!
typedef int array_t[3001];
array_t* array = new array_t[3001];
then you can do array[50][400], etc.
Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|