473,379 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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?
Jul 22 '05 #1
11 25344
"eggie2486" <eg******@twcny.rr.com> wrote...
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?


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
Jul 22 '05 #2
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" <eg******@twcny.rr.com> дÈëÓʼþ
news:hz****************@twister.nyroc.rr.com...
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?

Jul 22 '05 #3
.
eggie2486 wrote:
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?


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.
Jul 22 '05 #4
Eric Lee wrote:
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.


Just to nitpick:
1. Don't top-post.
2. Your program requires: sizeof(int) * 3001 * 3001, if this was
a true "square" area of memory. The big issue is that
sizeof(int) may not be 32 bits on all platforms. Some have
16 bit ints, others have 64 or larger.

--
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

Jul 22 '05 #5
.. wrote:
eggie2486 wrote:
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?


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.


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

Jul 22 '05 #6
Eric Lee wrote:
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.


32bit*3001*3001 is not 288M, it's approx 36M.

Plus sizeof(int) is not necessarily 32 bits.

- J.
Jul 22 '05 #7
"Jacek Dziedzic" <ja*************@janowo.net> wrote...
Eric Lee wrote:
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.


32bit*3001*3001 is not 288M, it's approx 36M.

Plus sizeof(int) is not necessarily 32 bits.


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
Jul 22 '05 #8
Victor Bazarov wrote:
That's all true. But if sizeof(int)*CHAR_BIT is not 32 (but
smaller, supposedly), then sizeof(int*) is smaller too, probably.


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*).
Jul 22 '05 #9
"Bill Seurer" <se****@us.ibm.com> wrote...
Victor Bazarov wrote:
That's all true. But if sizeof(int)*CHAR_BIT is not 32 (but
smaller, supposedly), then sizeof(int*) is smaller too, probably.
Why would you think that?


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.
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*).


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?
Jul 22 '05 #10
On Fri, 23 Apr 2004 00:37:33 GMT, "eggie2486" <eg******@twcny.rr.com>
wrote:
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?


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
Jul 22 '05 #11
On Wed, 28 Apr 2004 09:44:59 +0100, tom_usenet
<to********@hotmail.com> wrote:
On Fri, 23 Apr 2004 00:37:33 GMT, "eggie2486" <eg******@twcny.rr.com>
wrote:
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?


Allocate from the heap:

typedef int (*array_t)[3001];
array_t array = new array_t[3001];


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
Jul 22 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: chotiwallah | last post by:
there seems to be a maximum size (in px) for images created with imagecreatetruecolor (somewhere between 4000 px and 4500 px). if the image is bigger than that size, the browser doesn't display it...
7
by: Joey C. | last post by:
Hello, I'm designing a small "briefcase" program that will allow me to quickly upload, download, and delete files in a briefcase. The only real things that I have left to do are to design a...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
5
by: VMI | last post by:
How can I increase the maximum size of a Windows form? I'm trying to make a really big Windows form (about 1000x1000) but the designer doesn't allow me to do that. It only goes up to 1000x780....
6
by: Divick | last post by:
Hi all, how can I figure out what is the maximum size of data that can be allocated in static area on a particular architecture. I am using g++ on 64 bit Intel architecture and when I create a...
23
by: Gerrit | last post by:
Hi all, I'm getting an OutOfMemoryException when I initialize a byte array in C# like this: Byte test = new Byte; I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing...
7
by: tomlebold | last post by:
The file size of the Access application I'm currently working on is 77,000 MB. What is the maximum size the Access file or MDB can be?
2
by: Woody Ling | last post by:
I am now using db2 v8.2 64bits without DPF. I want to create a very large table which is about 1000G and the record length is suitable for 32K page size. I find in the manual that the maximum size...
3
by: skyy | last post by:
Hi.. what is the maximum size of an array and variable? With the following declaration: my $size; my @rx_array; what is the maximum number that $size can hold? what is the maximum number...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.