Jump to content
  • Advertisement
Sign in to follow this  
hdneto1700

Is there a size limit on a class?

This topic is 4830 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I initilized an array of integers in a class. I then made an array of a class (thus multiply arrays of that array). When the program tries to modify the array of integers it crashes. The strange thing is that it works fine until it reaches the third or fourth array value(there's 9 in all). Is there a limit on what a class can hold or is it that you can't make an array of a class that contains another array. Any help would be appreciated

Share this post


Link to post
Share on other sites
Advertisement
If you're instantiating your classes on the stack and not using dynamically allocated arrays (your array of integers in said class) you may be running out of stack space.

There is no limit on what a class can hold--and yes, you may instantiate arrays of classes which have an array as a member.

Share this post


Link to post
Share on other sites
As far as I know, there is no such limit either way. If it is an array of only 9 ints in the class, then how big is the array of classes(how many of the 9 int arrays?)? The only limit would be memory, in which case you would need to allocate for it using new or malloc() because each program only gets a small amount of memory in the RAM. For storing other things, big things, use new or malloc as they grab memory from the "heap" which includes all available memory on the computer and even maybe virual memory, though that is very slow(another story). Another issue is if for some reason, you are going out of bounds of the arrays. If it is an array of 9 ints and somewhere you try to access 10 or up in the array, it crashes with a general protection fault or something like that. If it isn't any of the above, post some code.

EDIT The above poster just beat me to it.

Share this post


Link to post
Share on other sites
Its actually a pretty large project so i can't post any codes.
The problem is when i make the class array three members, it works. But anything over makes the program crashes when it starts working on the forth class array member. But I think you guys were on to something.

Thanks alot.

Share this post


Link to post
Share on other sites
Of course there are limits.


template <int d> class foo
{
foo<d-1> bar, baz;
};

class foo<0>
{
int bar;
};

int main()
{
foo<500> goodbye_cruel_world;
}


Share this post


Link to post
Share on other sites
Quote:
Original post by smart_idiot
Of course there are limits.


Ah, but which limit did you hit? Template recursion limit? Class member count limit? Stack overflow?

Share this post


Link to post
Share on other sites
Quote:
Original post by Fruny
Quote:
Original post by smart_idiot
Of course there are limits.


Ah, but which limit did you hit? Template recursion limit? Class member count limit? Stack overflow?


What's funny is that if he would have used 498, it would have worked fine [smile] (Visual Studio 6) In Dev CPP you would see this:
Quote:
13 C:\Documents and Settings\Drew Benton\Desktop\main.cpp size of variable 'goodbye_cruel_world' is too large

I vote for the template recursion overflow.

Share this post


Link to post
Share on other sites
Nope, template recursion gives a different error. The problem is that the class is 1.30935624e151 bytes in size. It branches out as a tree 500 layers deep, and each leaf has an integer.

I think GCC's template recursion limit is 512 by default. The documentation says not to rely on more than 17 in a ISO C++ compliant program though, so. . .

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!