Re: Problem with const int.
You're probably running out of stack space.
Re: Problem with const int.
Quote:
Originally Posted by
GCDEF
You're probably running out of stack space.
Hi GCDEF,
How can I solve it.
Any quick and easy solution will be appreciated.
I am using MS Visual c++ 6.0
Re: Problem with const int.
Is this a local variable?
If so, you are trying to allocate 25,600,000 bytes on the stack.
(100000 * 32 * 8)
That is highly unlikely to work on any machine! The default on Windows machines is 1MB per thread (I think).
You will have to allocate from the heap, either with a 'new' or use a std::vector.
Re: Problem with const int.
Quote:
Originally Posted by
JohnW@Wessex
Is this a local variable?
If so, you are trying to allocate 25,600,000 bytes on the stack.
(100000 * 32 * 8)
That is highly unlikely to work on any machine! The default on Windows machines is 1MB per thread (I think).
You will have to allocate from the heap, either with a 'new' or use a std::vector.
Hello JohnW,
These are the local variables. Could you please give me an example? How to use heap?
My array is exactly A[100000][3]. So, it comes (100000 * 3 * 8)/(1024*1024) = 2.28MB.
Re: Problem with const int.
Using std::vector
Code:
#include <vector>
using namespace std;
int main()
{
const int i = 100000;
const int j = 32;
vector<vector<__int64>> A(i, vector<__int64>(j));
}
Though if you are going to have large 2D arrays then it is often better to wrap a 1D vector in a class and let the interface emulate the 2D aspect. In that way there is only one allocation of memory and a lot less heap fragmentation.
You can write your own fairly simply or Use Boost's multi_array.