Solved

maximum limit of array size

Posted on 2006-11-23
4
655 Views
Last Modified: 2012-06-22
what is the maximum limit of array size ?
e.g. array[n] ... wats the size of n?

i guess it should also depend on the type of array?
kindly clearify the concept

regards
0
Comment
Question by:fatimao
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 18006377
Essentially it's limited by the stack size.
The C++ language itself does not impose a limit afaik.
Apart from the machine limit of course : the size of an unsigned int - ie. the theoretical limit on a 32-bit machine would be 2^32 - 1. But you'd probably never get there anyway, because you'll hit memory constraints long before that :)

In any case, it's not good practice to create large static arrays (on the stack) - use dynamically allocated memory instead (on the heap).
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 50 total points
ID: 18006386
>> ie. the theoretical limit on a 32-bit machine would be 2^32 - 1
Let me clarify that. The theoretical limit for this array :

    T arr[N];

would be :

    N*sizeof(T) <= 2^32 - 1

or :

    N <= (2^32 - 1)/sizeof(T)

Again for a 32-bit machine with 32-bit unsigned ints.
0
 

Author Comment

by:fatimao
ID: 18012128
please can you tell what will be the limit of the stack size assigned to the process?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 18012180
The stack is a part of the process memory used for statically allocated memory (for function calls, local variables, etc.). Its size is entirely implementation/platform dependent and is not prescribed by the C++ standard.

In any case, you shouldn't depend on any value for that size - that's not a safe way to code. If you get to the limit of the stack, your program will generate a stack overflow.

As I said : if you have a lot of memory to allocate, DON'T do it on the stack, but on the heap (ie. dynamically allocated).

Do you know what a stack and heap are, and how process memory is organised ?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question