CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2003
    Location
    Chennai, India
    Posts
    76

    Maximum size of Structure

    Hi,

    Is there a constraint on the maximum size of the Structure that can be defined in VC++.

    Thanks in Advance,
    Varadha

  2. #2
    Join Date
    Sep 2003
    Location
    Chennai, India
    Posts
    76
    When i define the following struture
    typedef struct summa
    {
    int a;
    int b;
    char c[1062144];
    }summa;

    and run the application, i get the following error.

    Unhandled Exception: ..... Stack Overflow

  3. #3
    Join Date
    May 2000
    Location
    Scotland, Livingston.
    Posts
    728
    This is because its too big for the stack. You could allocate it with new and put it on the heap instead. Or you could increase the size of your stack in the linker options.
    Dave Mclelland.

  4. #4
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    Or use a std::string or std::vector<char> as a structure member, which essentially puts that memory on the heap.

    What problem are you trying to solve, or is the question academic?

    Jeff

  5. #5
    Join Date
    Sep 2003
    Location
    Chennai, India
    Posts
    76
    Thanks Dave and Jeff, as u have said the problem is size of the structure is beyond the stack size.
    How can i increase the stack size?
    Can u give me some online tutorial on this.

  6. #6
    Join Date
    Sep 2003
    Location
    Forever Gone... For Now...
    Posts
    1,515
    Originally posted by Varadha
    Thanks Dave and Jeff, as u have said the problem is size of the structure is beyond the stack size.
    How can i increase the stack size?
    Can u give me some online tutorial on this.
    MSDN "Visual C++ Linker Options":
    The /STACK option sets the size of the stack in bytes. This option is only for use when building an .exe file.
    That said, usually when one thinks they need to increase the stack size, it is because they are abusing the stack (char c[1062144];). Rethink your design.
    Thought for the day/week/month/year:
    Windows System Error 4006:
    Replication with a nonconfigured partner is not allowed.

  7. #7
    Join Date
    Sep 2003
    Location
    Forever Gone... For Now...
    Posts
    1,515
    [QUOTE]Originally posted by Andreas Masur
    In is case I would rather say that he needs the 'Zm' option...
    MSDN:
    /Zm (Specify Precompiled Header Memory Allocation Limit)
    Hi Andreas,

    I'm ignorant. Can you explain how that pertains to this?
    Thought for the day/week/month/year:
    Windows System Error 4006:
    Replication with a nonconfigured partner is not allowed.

  8. #8
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Originally posted by Varadha
    Thanks Dave and Jeff, as u have said the problem is size of the structure is beyond the stack size.
    How can i increase the stack size?
    Can u give me some online tutorial on this.
    However, as the others also pointed out, you seem to be abusing the stack here, and should rather allocate that amount of memory on the heap instead of increasing the stack size. Besides that, what is the use of a structure that amount of memory as a static character array? You should rather rethink your design (or explain why you need to do this).
    Last edited by gstercken; November 7th, 2003 at 09:39 AM.

  9. #9
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by vicodin451
    I'm ignorant. Can you explain how that pertains to this?
    No you don't...but I am stupid...forget about it, I was thinking about something different wile writing this...sorry about this...I already have deleted my nonsense...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured