windows class size limit?

I made a class, which need to have 16-17 variables in its private or protected section. Problem is, when I put in more than 14 variables, it compiles okay, but when the class is first used, Windows gives me a "Tester.exe has encountered a problem and needs to close" error. I have clearly linked this to the addition of a fifteenth variable. Any ideas?
More information is needed. Can you post the class difinition and the way you use it?
okay then here is the class(with 14 variables):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class dot{
	public:
		dot();
		dot(fgw::hue const);
		dot(int x, int y, int direction, fgw::hue const);
		void display(fgw::playpen &);
		void fire();
		fgw::hue move_forward(fgw::playpen &);
		void turn_left(fgw::playpen &);
		void turn_right(fgw::playpen &);
		void erase(fgw::playpen &);
		int x(){ return x_;}
		int y(){ return y_;}
		void take_a_firing_step(fgw::playpen  &);
		fgw::hue hit(){return hue_hit;}
		bool dead(){ return death;}
		void get_eaten();
		int dot_direction(){ return direction;}
		fgw::hue dot_color(){ return color;}
	private:
		int direction;
		int x_;
		int y_;
		fgw::hue hue_hit;
		fgw::hue color;
		bool death;
		bool fire_in_process;
		bool new_values_locked;
		int x1;
		int y1;
		int last_x;
		int last_y;
		fgw::hue last_hue;
		int firing_direction;
};
#endif 


I'm not sure that an example of how I use it would be informative, as it must be interweaved with at least one other class to be useful, however here is an example:
1
2
3
4
5
6
7
8
9
dot dr(0, 0 black);
if(keycode == key_up_arrow) dr.move_forward(pp);
if(keycode == key_right_arrow)dr.turn_right(pp);
if(keycode == key_left_arrow)dr.turn_left(pp);
if(keycode == key_space){
   ++times_player_fired;
   (!(times_player_fired > 1)) dr.fire();
   else if(times_player_fired > 2) times_player_fired = 0;
}


yes! the coding style is bad. I plan to clean it up shortly after i fix this...
I've slightly changed your code and managed successfully compile and execute it. Addition of 1, 2, 3, ... extra members changes nothing. Indeed, it would be strange if 14 were a magic number... Were it 13 i could believe, but not 14 :)

Did you trace your program in debugger?
Interestingly enough, the crash happens when i try to put ten of these into a map storage container. Could i possibly be overloading the maximum storage limit for the container?
EDIT: and agh, why did it put my message all in one line?
Last edited on
No, there is no "storage limit" aside from the amount of continuous space you have on your computer...try printing out "sizeof(dot)" and see how big it is (in bytes)
Well, sizeof(dot) reads 48. Seems kinda small
Ah, sorry, that will make it print out the size of the uninitialized class...make an instance of the class then print out sizeof(<instancename>). (Although I haven't actually ever tried this)
Just to point out with what firedraco said - his correct with his sizeof(<instancename>) - That will work fine
Well, even with creating an instance, it still reads 48. Hmm, and it seems I have left out something. I created an AI for this and the error happens when I put ten of those in to a map. sizeof(<instance of dot_ai>) reads 72.
EDIT: why does the website insist on spelling out my messages on one line?
Last edited on
Hm, well, the only reason I can think of is that you are either out of memory for your program, or you are accessing invalid memory (i.e. memory you don't own). If you can, try stepping through your program and seeing where the variables point...see if they are pointing at bad data (NULL or similar).
I stepped through it and it crashes on line 736 of the standard library file stl_tree.h
Have you looked at the variables/code around that area (look for pointers pointing to bad data, or really big allocations)? I would look at the file but apparently I don't have it...
What else are you using to make this game? Firedraco - if you want to check it out: http://www.sgi.com/tech/stl/stl_tree.h
Last edited on
I looked at the file and it's slightly different than the one that Mythios found to download. On that one, it's line 660.
if you are using map, make sure you have created a proper copy constructor. You don't seem to have one, maybe you are getting an unintentional cast somewhere. Make it a basic rule to always do a copy ctor, default ctor, a dtor and an assignment operator. last but not the least : make sure you are initializing all variables in your ctor.

what key are you using in the map? are you using your object as a key? map has no size restriction but if you are using the object as a key then you may need to provide some more member functions that allow the map to sort your objects since a map is a sorted associative container.
I think you are off by six lines. XD

The error isn't in the STL. anders has it exactly:

You must have a copy constructor.
You should probably also have an assignment constructor and a destructor.
(Google c++ the law of the big three)

Failure to copy means that your object will break the instant the map decides to move its memory around. Anything you stick in an STL container should have, at minimum, a copy constructor.

Hope this helps.
Last edited on
I wrote a copy constructor for the AI and for dot. It seems to be working now. Thanks to all who helped!
Topic archived. No new replies allowed.