Thread: getting more memory for the compiler to use, or something like that

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    getting more memory for the compiler to use, or something like that

    I keep getting these stack overflow errors. I can only declare 50 of my 'ROOM' variables. if i add more variables to struct ROOM, that number goes down. it seems like theres not enough memory for the compiler or something. im using MSVC++ 6.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    Try declaring it like:

    classname *ROOM = new classname[number_of_rooms];

    That will allocate enough memory if you have it.

  3. #3
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    im not sure what you mean by that. possibly explain more? im using structs though, struct ROOM

  4. #4
    Registered User Liam Battle's Avatar
    Join Date
    Jan 2002
    Posts
    114
    uh im pretty sure you didnt run outta memory...
    but i would dynamically allocate the struct when you are using them, that way you can check to see if the allocation worked, and if not then try reducing the size of the allocation...

    in C++ is much better to dynamically allocate everyting, altho its tad slower for certain things, it gives you more control and felxibility with you code...
    LB0: * Life once school is done
    LB1: N <- WakeUp;
    LB2: N <- C++_Code;
    LB3: N >= Tired : N <- Sleep;
    LB4: JMP*-3;

  5. #5
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Hmmm, that's a tough one -

    struct*ROOM = new ROOM[number_of_rooms];

    or you could could set up your compiler to allocate more stack space (and before you ask someone how to do this, try reading a few manuals, or searching on google).

    Or you could use any one of the standard container classes.

    Or you could jack it all in.

  6. #6
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Why is it better to dynamically allocate everything? Each pointer is 4 bytes + size of the object you're creating. Also, you have the overhead of deleting each one of the variables, instead of letting them take their own course of action and go out of scope.

  7. #7
    ‡ †hë Ö†hÈr sîÐè ‡ Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    Originally posted by Dual-Catfish
    Why is it better to dynamically allocate everything? Each pointer is 4 bytes + size of the object you're creating. Also, you have the overhead of deleting each one of the variables, instead of letting them take their own course of action and go out of scope.
    This will work with small objects, in small applications.
    BUT you have a limited stack. I'm not sure how big it is, if anyone knows please post it.
    You are receiving a "stack overflow" message b/c .....umm......Its self explanatory.
    You put too much in your stack. Think of it like an array.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  8. #8
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    actually i solved it a different, much easier way. declare each room as a static variable.

  9. #9
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Having to manage 50 seperate variables (without them being consolidated into an array) is an easy solution I think...
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  10. #10
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    was that supposed to be sarcastic....that IS what im doing. now i can have all 55 rooms. i never knew that when a variables is instantiated as static that it isnt put onto the stack.

  11. #11
    Registered User Prodigy's Avatar
    Join Date
    May 2002
    Posts
    25
    ok leem man s plz change ur avatar i spent 2 hours!!!!!!!!!!! looking for that!!!!! i mean ur a senior u should have ur own
    And the cows moo...
    AIM:ProdigyCpp
    E-Mail:[email protected]
    If you like my avatar plz dont copy it go to:
    http://www.dragid.com/

  12. #12
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    It wasn't sarcastic.. but I meant to have a not in there .
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with shared memory shmdt() shmctl()
    By Jcarroll in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 10:48 PM
  2. Relate memory allocation in struct->variable
    By Niara in forum C Programming
    Replies: 4
    Last Post: 03-23-2007, 03:06 PM
  3. Copying memory, pointers and the like.
    By psychopath in forum C++ Programming
    Replies: 34
    Last Post: 12-12-2006, 01:37 PM
  4. Memory allocation and deallocation
    By Micko in forum C++ Programming
    Replies: 3
    Last Post: 08-19-2005, 06:45 PM
  5. Accessing Video Memory Information...need help
    By KneeLess in forum C++ Programming
    Replies: 8
    Last Post: 08-24-2003, 03:53 PM