LINK : fatal error LNK1248: image size exceeds max

2019-01-27 01:22发布

I am doing some extremely large array processing. I do a global declaration of:

`float array[200][1600][811];`

When I build my solution in MS Visual Studio 2010, I get the following error

LINK : fatal error LNK1248: image size (F85C8000) exceeds maximum allowable size (80000000)

Now, I am aware this amounts to about 1 GB of program memory. But this declaration worked for a declaration of float [50][1600][811] which amounts to 250 MB. I know the default stack size is very limited. There are a couple of things I have already tried. I increased the stack size in VS through Properties -> Linker -> Stack reserved size. This didnt help. I changed my executable to run in x64 mode (which is said to address upto 2GB memory!). This didnt help either.

I do not wish to do a malloc on the array because I know for sure I need them in my code. I had to make them global declarations so that I can avail the stack/heap memory. If I declare them inside my Main (), it gives me error of memory overflow.

Any pointers would be greatly appreciated. Thanks.

2条回答
别忘想泡老子
2楼-- · 2019-01-27 01:57

It appears that even when you're building an x64 executable, the linker has limits more appropriate for an x86 build. Not much you can do about that.

The only solution is to allocate it from the heap. This should be usable in the same way as your original declaration.

typedef float partial_array[1600][811];
std::unique_ptr<partial_array> array = new partial_array[200];
查看更多
冷血范
3楼-- · 2019-01-27 02:14

If you are malloc adverse, you have two immediately obvious possibilties. C++11 has a nice array type which might help:

std::array<std::array<std::array<float, 50>, 1600>, 811> matrix;

Or you could consider using std::vector with a loop to initialise all the values correctly:

std::vector<std::vector<std::vector<float>>> matrix;
matrix.reserve(50);

for (size_t i = 0; i < 50; i++)
{
    std::vector<std::vector<float>> submatrix;
    submatrix.reserve(1600);

    for (size_t j = 0; j < 1600; j++)
    {
        std::vector<float> row;
        row.resize(811);

        submatrix.push_back(row);
    }

    matrix.push_back(submatrix);
}
查看更多
登录 后发表回答