Archived

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

johndunne

getting Class sizes

Recommended Posts

Evening all, Does anyone know a quick way of determining exactly how much space in memory a class is using up? Or what about any programs that can tell you how much memory your game is using. I''m writing a game in DirectX using VC++ 6 and at the moment its eating up over 80 MBs, thats without ANY sounds loaded or DirectSound initialised! And i''m only using 7 small meshes at any one time (each around 30kb big.)

Share this post


Link to post
Share on other sites
Cheers burning ice, I usually use sizeof() but does it include the methods within the classes? What i''m really after is a way to cut back the amount of memory in use and a way to optimize the code, ideas? What does everone out there use?

Share this post


Link to post
Share on other sites
count it manually...


class widget
{
public:
long SizeOf() { return size; }
void Init(int howmany)
{
mini_widget = (custom_struct*) new custom_struct[howmany];
size = sizeof(custom_struct) * howmany;
}
private:
long size
custom_struct *mini_widget;
};


this way you could even see how much memory you''ve allocated
per class and per object.
revised example

class widget
{
public:
static long totalsize;
long SizeOf() { return size; }
void Init(int howmany)
{
mini_widget = (custom_struct*) new custom_struct[howmany];
size = sizeof(custom_struct) * howmany;
totalsize += size;
}
widget() { // increase size // }
widget(const widget &widgie) { // same with copy constructor // }
private:
long size
custom_struct *mini_widget;
};

long widget::totalsize = 0;


now widget::totalsize will tell you how much memory (total) you''re
using for that class, and instance_widget.SizeOf() will return
the size of that particular object..

this is all pseudo code by the way, so i wouldnt advice copy/pasting without some heavy editing

-eldee
;another space monkey;
[ Forced Evolution Studios ]


::evolve::

''In C we had to code our own bugs. In C++ we can inherit them.''

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The sizeof method will only calculate the size of the class member variables (including the vtable if there is one), not the code, as there is only one copy of a class''s code in memory per process, the chances of your code taking up 80MB is highly unlikely...

Share this post


Link to post
Share on other sites
methods don''t take any space. only data members do, and only if you use virtual functions then your class will have a vtable(4 bytes)

so i guess it''ll rather be the case that you have a real lot of uneccessary stuff allocated. check your arrays, epsecially those that get new''d at runtime, and make sure you only allocate as much as you need.

80 megs is really a lot, and since you say your models need only a couple kb i really think there''s some point in your code where you allocate way more then you actually want.


you can overload your new and delete operators (or search for some free memory manager on the web) to see where, and how much, memory gets allocated.





Runicsoft -- home of my open source Function Parser and more

Share this post


Link to post
Share on other sites