C++ Eclipse Question

JC0133

Senior member
Nov 2, 2010
201
1
76
First off I am running my program in Eclipse on Virtual box in Linux.

My program crashes when I add an additional array. I have not even used this array. So I am wondering if I am using too much memory.

Here are my data structures I create at the top of the program.

//used in task 0
class CFG_Rules {

public:
string LHS;
string RHS[500];
int ruleNumber;
};

//used in task 1
class CFG_Rules1 {

public:
string LHS;
string RHS[500];
int numberOfRHSeachRule;
};
//used in task 1
class FIRST_SETS {

public:
string firstSetsNonTerminals;
vector<string> vFirst;
set<string> sFirst;
int numberOfSets;
};

//used in task 1
class CFG_Rules2 {

public:
string LHS;
string RHS[500];
int numberOfRHSeachRule;
};

//used in task 2
class FOLLOW_SETS {
public:
string followSetsNonTerminals;
set<string> sFollow;
int numberOfFollowSets;
};



I create some arrays in main here

//creating data structure of rules
CFG_Rules myRules[1000];
//creating data structure of rules for task1
CFG_Rules1 myRules1[1000];
//creating data structure of First Sets for task 1
FIRST_SETS firstSets[1000];
//creating data structure of rules for task2
FOLLOW_SETS followSets[1000];

The issue comes here

the entire program works.

But once I create this array
CFG_Rules2 myRules2[1000];

The program crashes when I run it.

I don't even use this array. When I remove it, the program works when I run it.

Any ideas of what is happening?? Am I running out of memory in Eclipse??
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,250
3,845
75
1000 objects, each containing 500 strings, times at most 5? That's 2,500,000 strings. Which, on one hand, is a large number, but on the other hand, if the strings were 400 bytes, they'd all fit in a gigabyte.

You might be running out of stack space (for local variables), as opposed to heap space. If you create the rules arrays with new, you might find you have a lot more space. You could also delete the arrays when you're done with them, as their use appears to be sequential.

But do you really need a fixed size, for the inner arrays of Strings in particular?