Array limits

M

maaceroo

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

osmium

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><delete> calls.
 
V

Victor Bazarov

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
 
V

Victor Bazarov

osmium said:
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><delete> calls.

Just a nit pick: I don't think the OP mentioned 'new' or 'delete'...

V
 
M

maaceroo

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

I'm actually asking about the maximum size of each dimension.
Thanks a lot.

MarioAAO
 
V

Victor Bazarov

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
 
M

maaceroo

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


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

Best,
MarioAAO
 
J

Joe Greer

(e-mail address removed) wrote in @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
 
D

dilip

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top