473,320 Members | 1,958 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,320 software developers and data experts.

Array limits

Hello,
I am not an expert in programmig, and I'm experimenting some problems
I hope you could help me to solve.
By now, I would like to know if in C++ there is a maximum number of
rows (and columns) which can be stored in an multi dimensional) array.

I apologize if this is a very basic question, but I've not found
information about this in any other place.

Thanks in advance for your help.
Regards,

MarioAAO.

Aug 30 '07 #1
8 2360
<ma******@gmail.comwrote:
I am not an expert in programmig, and I'm experimenting some problems
I hope you could help me to solve.
By now, I would like to know if in C++ there is a maximum number of
rows (and columns) which can be stored in an multi dimensional) array.

I apologize if this is a very basic question, but I've not found
information about this in any other place.
There definitely is a maximum but it is related to your operating system. I
would forget about the two dimensional aspect and see when new fails in a
series of <new><deletecalls.
Aug 30 '07 #2
ma******@gmail.com wrote:
I am not an expert in programmig, and I'm experimenting some problems
I hope you could help me to solve.
It is better if you actually describe the problems instead of trying
to guess what causes them...
By now, I would like to know if in C++ there is a maximum number of
rows (and columns) which can be stored in an multi dimensional) array.

I apologize if this is a very basic question, but I've not found
information about this in any other place.
Are you asking the maximum number of dimensions or the maximum size of
each dimension? The former probably differs with compilers, the latter
is controlled by the computer memory when executing the program, and
the maximum value of 'std::size_t' type. Usually, statically allocated
arrays can be bigger than automatically allocated ones. Dynamically
allocated arrays are usually the least constrained.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 30 '07 #3
osmium wrote:
<ma******@gmail.comwrote:
>I am not an expert in programmig, and I'm experimenting some problems
I hope you could help me to solve.
By now, I would like to know if in C++ there is a maximum number of
rows (and columns) which can be stored in an multi dimensional)
array. I apologize if this is a very basic question, but I've not found
information about this in any other place.

There definitely is a maximum but it is related to your operating
system. I would forget about the two dimensional aspect and see when
new fails in a series of <new><deletecalls.
Just a nit pick: I don't think the OP mentioned 'new' or 'delete'...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 30 '07 #4
Are you asking the maximum number of dimensions or the maximum size of
each dimension? The former probably differs with compilers, the latter
is controlled by the computer memory when executing the program, and
the maximum value of 'std::size_t' type. Usually, statically allocated
arrays can be bigger than automatically allocated ones. Dynamically
allocated arrays are usually the least constrained.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I'm actually asking about the maximum size of each dimension.
Thanks a lot.

MarioAAO

Aug 30 '07 #5
ma******@gmail.com wrote:
>Are you asking the maximum number of dimensions or the maximum size
of each dimension? The former probably differs with compilers, the
latter is controlled by the computer memory when executing the
program, and the maximum value of 'std::size_t' type. Usually,
statically allocated arrays can be bigger than automatically
allocated ones. Dynamically allocated arrays are usually the least
constrained.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

I'm actually asking about the maximum size of each dimension.
Thanks a lot.
What you want to figure out is how big the array is. It is relatively
simple, use sizeof(your array type). For example, if you want to try
to allocate int [123][456], see how big is:

std::cout << sizeof(int[123][456]);

Essentially it's sizeof(int)*123*456. Now, whether it fits into the
memory structure in which you hope to place it, is a different story.
For example, on many platforms nowadays "automatic" objects are
allocated on the "stack", the size of which is usually controlled by
a command-line switch of the linker (or you use the default). It is
often too small for anything large. In that case use dynamic memory
(free store). See the FAQ on how to allocate a two-dimensional array
in the free store.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 30 '07 #6
On Aug 30, 8:37 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
maace...@gmail.com wrote:
Are you asking the maximum number of dimensions or the maximum size
of each dimension? The former probably differs with compilers, the
latter is controlled by the computer memory when executing the
program, and the maximum value of 'std::size_t' type. Usually,
statically allocated arrays can be bigger than automatically
allocated ones. Dynamically allocated arrays are usually the least
constrained.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I'm actually asking about the maximum size of each dimension.
Thanks a lot.

What you want to figure out is how big the array is. It is relatively
simple, use sizeof(your array type). For example, if you want to try
to allocate int [123][456], see how big is:

std::cout << sizeof(int[123][456]);

Essentially it's sizeof(int)*123*456. Now, whether it fits into the
memory structure in which you hope to place it, is a different story.
For example, on many platforms nowadays "automatic" objects are
allocated on the "stack", the size of which is usually controlled by
a command-line switch of the linker (or you use the default). It is
often too small for anything large. In that case use dynamic memory
(free store). See the FAQ on how to allocate a two-dimensional array
in the free store.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Good,
Thanks a lot. I'll check it.

Best,
MarioAAO

Aug 30 '07 #7
ma******@gmail.com wrote in news:1188497898.949547.58080
@q4g2000prc.googlegroups.com:
Hello,
I am not an expert in programmig, and I'm experimenting some problems
I hope you could help me to solve.
By now, I would like to know if in C++ there is a maximum number of
rows (and columns) which can be stored in an multi dimensional) array.

I apologize if this is a very basic question, but I've not found
information about this in any other place.

Thanks in advance for your help.
Regards,

MarioAAO.
Technically, the grammer allows you to use the largest available
constant integral expression you can write. This value will be
implementation dependant. MS for example, limits arrays to 2147483647
bytes total (in reality, it complains until it's less than 2147483640)
and will complain if you try to allocate something bigger than that.
That means for any type T, the MS compiler will allow you to declare
arrays up to 2147483640 / sizeof T elements for single dimension arrays.
It is apparently not so simple for multi-dimensional arrays because char
a[2][1073741820] doesn't work. In any case, the point is that the
absolute max is implementation dependent, but pretty large.

What you also have to ask is what kind of impact allocating that much
memory will have on your program. With large arrays like that, you
really need to be worried about locality of reference (or the virtual
memory system with thrash about and slow you down).

Hope that helps in some way,
joe
Aug 30 '07 #8
hi friends
There is no such maximum numbers for array initialization for any
dimensional array.
It basically depends upon your OS and memory available.
Because at the time of accessing these elements their is no bound
checking for last limit.
That's why is throws ArrayIndexOutOfBound Exception in Java or
exception in C++ we have to manage.
Accessing these elements refer to accessing memory where element is
stored.Hence it's depend upon the available memory of Computer and OS.
Thanks,
Dilip Kumar
http://www.intelcs.com/IT-Companies/

Aug 31 '07 #9

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

Similar topics

7
by: mabauti | last post by:
I need to have two arrays with 480,000 elements each. When I try to execute the program that contains this command I receive an error window (in Windows) ( "error using miprogram_in_c.exe" ). What...
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
8
by: Gerald | last post by:
I have a problem with an array of pointers. In a program I'm writing, I have to read a file, containing thousands of short lines. The content of another file will be compared against each line...
11
by: mike | last post by:
hi, i am running a very big code on my pc using redhat linux. when i try to increase my array size, compile and run, i get segmentation fault. i go into the debugger, run it, it crashes right...
37
by: Carol Depore | last post by:
How do I determine the maximum array size? For example, int a works, but a does not (run time error). Thank you.
19
by: DarelRex | last post by:
Is it possible to pass a 2-D, statically defined array? Here's a 1-D example that won't work: void foo() { int myArray ; bar(myArray); } void bar(int *arr) {
15
by: prakash437 | last post by:
hello everyone, I have asked a similar question on the C++ group, however, i did not get the answer i was expecting ... How can i use a unsigned char array (of size, say 10 characters) as a set...
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
25
by: biplab | last post by:
Hi all, I am using TC 3.0..there if I declare a integer array with dimension 162*219...an error msg saying that too long array is shown....what should I do to recover from this problem???
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.