0

I have a little problem here, i write c++ code to create an array but when i want to set array size to 100,000,000 or more i got an error.

this is my code:

int i=0;
double *a = new double[n*n];

this part is so important for my project.

4
  • @talnicolas: How would that help? Commented Feb 23, 2012 at 16:59
  • 4
    What is the error? And, what is the value of n supposed to be in that code? Commented Feb 23, 2012 at 17:00
  • 1
    You need to bone up on sparse arrays. Commented Feb 23, 2012 at 17:01
  • i got this error when i put this part in try : External component has thrown an exception Commented Feb 23, 2012 at 17:46

3 Answers 3

1

When you think you need an array of 100,000,000 elements, what you actually need is a different data structure that you probably have never heard of before. Maybe a hash map, or maybe a sparse matrix.

If you tell us more about the actual problem you are trying to solve, we can provide better help.

Sign up to request clarification or add additional context in comments.

1 Comment

i don`t know this description is useful or not by the way this code is a little part of an FEM(finite element method) solver and i use IMSL Mathematical library to solve my linear system of equation and because of function that i want to use i need an native array with this size
1

In general, the only reason that would fail would be due to lack of memory/memory fragmentation/available address space. That is, trying to allocate 800MB of memory. Granted, I have no idea why your system's virtual memory can't handle that, but maybe you allocated a bunch of other stuff. It doesn't matter.

Your alternatives are to tricks like memory-mapped files, sparse arrays, and so forth instead of an explicit C-style array.

1 Comment

i use at least 1.2 GB memory for other stuff i my program before arrive this code line.
0

If you do not have sufficient memory, you may need to use a file to store your data and process it in smaller chunks.

Don't know if IMSL provides what you are looking for, however, if you want to work on smaller chunks you might devise an algorithm that can call IMSL functions with these small chunks and later merge the results. For example, you can do matrix multiplication by combining multiplication of sub-matrices.

1 Comment

i need this array to filled an passed to IMSL function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.