-1

This question is similar to other posted about /bigobj issues, however, these did not directly address the compiler options in general. This specifically answer the general question of compiler options, and handles the separate issue of the specific compiler option as well, and even goes further to link other similar questions in order to be more easily found than the others.

I need to initialize a struct with over 16641 elements.

    #include "stdafx.h"
    #include <iostream>

    struct ArtificialIdiocy{
        double x, y, z;
        double nx, ny, nz;
    };

    int _tmain(int argc, _TCHAR* argv[]){
        ArtificialIdiocy objectArray[16641];

        objectArray[0].x = 1.012709;
        objectArray[0].y = 0.069911;
        objectArray[0].z = 1.010933;
        objectArray[0].nx = 0.165410;
        objectArray[0].ny = 0.883572;
        objectArray[0].nz = -0.438063;

        objectArray[1].x = -1.000000;
        objectArray[1].y = 0.014457;
        objectArray[1].z = 1.000000;
        objectArray[1].nx = 0.179296;
        objectArray[1].ny = 0.883511;
        objectArray[1].nz = -0.432661;

        objectArray[2].x = 1.000693;
        objectArray[2].y = 0.011744;
        objectArray[2].z = -1.000509;
        objectArray[2].nx = 0.172582;
        objectArray[2].ny = 0.897122;
        objectArray[2].nz = -0.406629;

// so on, and so on....

        objectArray[16638].x = 0.969018;
        objectArray[16638].y = 0.116736;
        objectArray[16638].z = 0.967181;
        objectArray[16638].nx = 0.437513;
        objectArray[16638].ny = 0.782861;
        objectArray[16638].nz = 0.442335;

        objectArray[16639].x = 0.968575;
        objectArray[16639].y = 0.105999;
        objectArray[16639].z = 0.998326;
        objectArray[16639].nx = 0.561235;
        objectArray[16639].ny = 0.718528;
        objectArray[16639].nz = 0.410718;

        objectArray[16640].x = 0.999139;
        objectArray[16640].y = 0.089730;
        objectArray[16640].z = 0.997266;
        objectArray[16640].nx = 0.608631;
        objectArray[16640].ny = 0.688559;
        objectArray[16640].nz = 0.394208;

But the MSVS2013 compiler tells me that my struct has to many sections and quits with an error stating:

Error 1 error C1128: number of sections exceeded object file format limit : compile with /bigobj

How do I edit/add the "/bigobj" compiler switch?

halfer
  • 19,824
  • 17
  • 99
  • 186
JoryRFerrell
  • 33
  • 2
  • 16
  • 6
    This honestly looks like a maintenance nightmare waiting to end up on the Daily WTF. You should at least move this out to an external resource that's loaded at run-time. – The Forest And The Trees Dec 19 '13 at 21:54
  • @The Forest And the Trees I was not intending to use this in the full program. It is just and example of the very basic problem. :P I didn't want to add a lot of other code to the example because that would obfuscate the issue for potentially new programmers. In realistic operation, I intend to have this as part of a constructor within a larger struct, which is stored in a separate header file. Each character, object, etc., will be initialized from this header file. – JoryRFerrell Dec 19 '13 at 22:05
  • 1
    A major part of the problem might be placing a single 780KB array on the stack, when 1024KB is a common stack limit. – Mooing Duck Dec 19 '13 at 22:39
  • @Mooing Duck How should I handle initializing a large object such as this then? I would be creating a buffer object from it and then freeing the memory. What other ways could I handle it? – JoryRFerrell Dec 19 '13 at 23:49
  • Either put it in global memory (initialized more or less as you have it) or on the heap (initialized at run-time from some non-code resource). – Mooing Duck Dec 19 '13 at 23:51
  • @Mooing Duck Ahh...I am new to C++. Migrated from Python so still adjusting to the idea of multiple arena's of memory. Thank you for the pointer. – JoryRFerrell Dec 19 '13 at 23:55

1 Answers1

1

For MSVS Express 2013, open your projects "Property Pages", go to the "C/C++" tree item, and then go down to where you see the very last option, "Command Line". Click on this, and add any additional switches in the "Additional Options" text-box.

In this case, you would add "/bigobj", all lower-case letters.

See also:

Penalty of the MSVS compiler flag /bigobj

Build issue with MSVS 2010 and the C++ standard

How to compile with /bigobj within Dymola (Modelica)

Just found the following while linking this question to others:

http://msdn.microsoft.com/en-us/library/ms173499%28v=VS.100%29.aspx

http://msdn.microsoft.com/en-us/library/8578y171.aspx

Community
  • 1
  • 1
JoryRFerrell
  • 33
  • 2
  • 16
  • 5
    The search optimisation in this question is [currently under discussion at meta](http://meta.stackexchange.com/questions/212752/strange-search-engine-optimization-in-answers) – Richard Tingle Dec 19 '13 at 23:54