Archived

This topic is now archived and is closed to further replies.

Jesper T

Error: class too large (msvc++.net)

Recommended Posts

I got this error after making some changes in a class in a win32/OpenGL app. According to msdn this happens when class exceeds 64k limit. But the class isnt very large, it has 12 functions, one integer data member, and two arrays of an other class. Thanks in advance for any help. Here is the class code:
class RobotContainer {
public:
	RobotContainer(void);

	int	getFree(int, Lights *, OpenGL *, Audio *, Projectiles *);
	void createRobotType(int, int, Lights *, OpenGL *, Audio *, Projectiles *);
	Robot *getPlayerShip(Lights *, OpenGL *, Audio *, Projectiles *);

	Robot *getArray(void);

	void load(ifstream &);
	void save(ofstream &);

	void loadTypes(ifstream &);

    void update(float, Cube *, ObjectInfo &);
	void drawBody(Lights *, OpenGL *); 
	void drawWeapons(float, Cube *, ObjectInfo &);
    
	~RobotContainer(void);
	
	int num_types;

	Robot baseRobots[MAX_ROBOT_TYPES];
	Robot gameRobots[MAX_ROBOTS];
};

/* The error occured after I added the ''Projectiles *'' at the end of some of the functions argument list*/ 

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
so large big is it then?
just trace sizeof(Robot)*(MAX_ROBOT_TYPES + MAX_ROBOTS) and se what you get

Share this post


Link to post
Share on other sites
64k limit cant possibly mean that the class cant contain more than 64k of data??

I have other classes that must be vastly larger, so why is there a problem with this one?

[edit: correcting the wrongs]

[edited by - Jesper T on October 9, 2003 4:00:09 PM]

Share this post


Link to post
Share on other sites
Replace
Robot baseRobots[MAX_ROBOT_TYPES];
Robot gameRobots[MAX_ROBOTS];


With
std::vector<Robot> baseRobots;
std::vector<Robot> gameRobots;


And, your constructor with
RobotContainer()
: baseRobots(MAX_ROBOT_TYPES), gameRobots(MAX_ROBOTS)
{}



As a rule, it is a bad idea to have huge chunks of data in the body of your class.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
Thanks for the advise.

Whats the deal with the 64k limit? It cant be a limit to the tatal data amount, so is it a limit to the amount of functions and data members or something?

I just found a bug in a sub class of the Robot class which caused the problem btw.

Share this post


Link to post
Share on other sites
quote:
Original post by Jesper T
Thanks for the advise.

Whats the deal with the 64k limit? It cant be a limit to the tatal data amount, so is it a limit to the amount of functions and data members or something?

It''s a limit to the total data amount. Objects may be created on the stack, and it''s a bad idea to have large amounts of anything on the stack. Anytime you''re allocating significant amounts of memory, do it on the heap.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
I dont get it, this works fine:


class BigClass {
public:
__int64 data[10000][10000];
};

BigClass BC;

int _tmain(int argc, _TCHAR* argv[])
{
BC.data[rand()%16777216][rand()%15] = 123456789;

cout << "Works fine\n";

cin.ignore(1 ,''\n'');

return 0;
}


and __int64 data[10000][10000] is quite a bit larger than 64k..

Share this post


Link to post
Share on other sites
Don''t you dear question the power of Microsoft! ;-P

Well, even if it works, you should not create that ammount of memory on the stack. It''s okay for single variables or shorter strings, but when it comes to that things, please do it with :


int * pMyData = new int[10000];
...
delete[] pMyData;
/* or */

std::vector<int> intVector(10000);



It''s like driving a car in 200km/h, it might work well one or two times, but you can''t make it a habbit

----------------------------------------------
Petter Nordlander

"There are only 10 kinds of people in the world. They who understand binary and those who do not"

Share this post


Link to post
Share on other sites