Search code examples
c++visual-studio-2010dlllinkerextern

Maximum array size allowed for an extern array in C++ on Visual Studio 2010


I asked a question yesterday which is found here trying to understand any potential problems with using large lookup tables specified via an extern array. These tables are all used for a set of nonparametric models that must be built into a DLL for our customer to use, where the DLL is expected to make computations with the at say 1000Hz or so.

Now in my project, the assortment of extern array lookup tables in total store about 66.2M floats, so in total around 265MB of data. The project, with all these tables, will compile fine but fail to complete the linking. However, the project compiles and links fine when I have less than about 180MB of data stored in the extern arrays.

Since my post yesterday, I have gathered a lot of evidence suggesting my project is hitting a limit on the amount of data I can have stored in extern arrays. Is there any actual limit with how much data can be stored in a set of extern arrays/variables? Is there maybe a bug in the linker that could break by having too much data in extern arrays? If there is some limit, is there a way to bump the limit to something higher or work around this issue somehow?

Note that my project is a Win32 project.

Edit

Note that more info about the problem, like the error that appears, is in my link at the start of the post. Below is some screen shots of the pop-up and message in VS 2010:

Pop-up of Incremental Linker Failing

Visual Studio Linking Output after Incremental Linker Fails


Solution

  • For array this large you should use dynamic memory instead of arrays. Arrays are allocated on stack or the data segment, in your case. In fact, anything larger than around 100KB shall never be allocated as array. It can cause all kinds of trouble. And even if you did get the program running, there's likely to be some severe performance penalty.