Array

M

mabauti

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 is the
array element size limit for c++? What can I do in order to have a two
480K array elements?
 
J

John Harrison

mabauti said:
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 is the
array element size limit for c++? What can I do in order to have a two
480K array elements?

Use a vector instead of an array. You don't say what type your array is,
I'll assume it is an int array.

#include <vector>

std::vector<int> one_big_vector(480000);
std::vector<int> another_big_vector(480000);

int main()
{
// do whatever with the vectors
}

You can use vectors pretty much like arrays (and a whole lot more).

But you are dealing with very large amounts of memory still, so I can't
guarantee that this will work or that it is a sensible thing to do. The
other option is to redesign your program so that it doesn't need so much
memory or so that it doesn't need so much memory in a contiguous block. If
you explain why you need so much memory then maybe I will be able to suggest
some improvements.

john
 
C

Chris Theis

mabauti said:
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 is the
array element size limit for c++? What can I do in order to have a two
480K array elements?

Did you declare the arrays statically? You should consider using dynamic
memory allocation or use one of the standard library´s containers. However,
what exactly do you need such big arrays for? Are you sure that this problem
can´t be optimized so that you´ll get along with a lower number of elements?

Cheers
Chris
 
J

JKop

mabauti posted:
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 is the
array element size limit for c++? What can I do in order to have a two
480K array elements?


int array1[480000];
int array2[480000];

or:

int* p_array1 = new int[480000];
int* p_array2 = new int[480000];


-JKop
 
T

Thomas Matthews

mabauti said:
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 is the
array element size limit for c++? What can I do in order to have a two
480K array elements?

The C++ language specifies a minimum capacity for arrays in order
for compliance. Each implementation may exceed that minimum.
For example, if the C++ language said that a platform must support
100 integer elements, a platform is allowed to support 1024
integer elements. A non-conforming platform can support less
than the minimum. In either case, the compiler manufacturer
must state what the maximum capacity is for an array. These
values must be stated for automatic, local and dynamically
allocated arrays.

So, check your compiler documentation to see what the limits
are. You could experiment too. Generally, compilers have
smaller limits on automatic and locally declared arrays than
dynamically allocated arrays.


--
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.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
R

Ron Natalie

Thomas said:
The C++ language specifies a minimum capacity for arrays in order
for compliance.

It does not. Both the C and C++ recommendations for implementation
limits are "informative" and have no bearing on compliance.
 
M

mabauti

Ron Natalie said:
It does not. Both the C and C++ recommendations for implementation
limits are "informative" and have no bearing on compliance.

Thank you.
I solved my problem by using dynamic memory allocation
 
J

Jerry Coffin

Ron Natalie said:
It does not. Both the C and C++ recommendations for implementation
limits are "informative" and have no bearing on compliance.

In the case of C++, I believe that's correct. C, however, does have
_some_ normative lower limits, including the fact that:

The implementation shall be able to translate and execute at
least one instance of every one of the following limits:
....
65535 bytes in an object (in a hosted environment only).

OTOH, meeting the requirement only requires being able to execute one
specific program with a 64K object, not all possible programs that
contain it -- and I don't even see a requirement for documentation of
this particular program either. As such, the requirement is weak
nearly to the point of unenforceable, but normative nonetheless.
 

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,183
Messages
2,570,966
Members
47,516
Latest member
ChrisHibbs

Latest Threads

Top