How to find a STL class size?

W

webinfinite

Hi,

How to find a STL class size, for example: string. I would like to
know what the size of the implementation of this class, I am not
interested in the size of its object but the class itself. There are
discussion regarding addition of all the data member of the class/
structure to find out its size, but is there a neat way to find out
class' size?

Thank you very much for your attention.
 
V

Victor Bazarov

How to find a STL class size, for example: string. I would like to
know what the size of the implementation of this class, I am not
interested in the size of its object but the class itself. There are
discussion regarding addition of all the data member of the class/
structure to find out its size, but is there a neat way to find out
class' size?

What is "the size of the implementation of this class" as _opposed_
(by you) to "the size of its object"? What do you count as part of
the "implementation"? If you want to know how much memory is taken
away by an object (including the dynamic memory it allocates), there
is no "neat way" to do that, but your OS could be of some help or
you could use some OS-specific tools to see how much memory remains
available before and after the operation.

V
 
G

Guest

Hi,

How to find a STL class size, for example: string. I would like to
know what the size of the implementation of this class, I am not
interested in the size of its object but the class itself. There are
discussion regarding addition of all the data member of the class/
structure to find out its size, but is there a neat way to find out
class' size?

A class does not have a size since it does not exist anywhere than in
your source code. The only way to measure the size of a class would be
to count the number of characters or lines of code that is used in its
definition.
 
W

webinfinite

A class does not have a size since it does not exist anywhere than in
your source code. The only way to measure the size of a class would be
to count the number of characters or lines of code that is used in its
definition.

I am sorry not stating my question clearly. My intention is to find
out how many memory is consumed by a class definition. What kind of OS
tool will give me such information?
 
V

Victor Bazarov

I am sorry not stating my question clearly. My intention is to find
out how many memory is consumed by a class definition. What kind of OS
tool will give me such information?

A class definition exists only in C++ source. Once the program is
created from the source, there is no such thing as "class definition".
Perhaps it's time you acquaint yourself with the way compilers work.
It would require knowing how computers work, as well. "Inside the
C++ Object Model" by Lippman is a good book to start with.

V
 
B

bjeremy

I am sorry not stating my question clearly. My intention is to find
out how many memory is consumed by a class definition. What kind of OS
tool will give me such information?

Well... like Erik and Victor said.. you cannot get the memory consumed
by a "class definition"... but a good tool if you are on a Linux
distribution is the Valgrind framework... among its toolsets is a
memory checker... (they have a neat profiler too)...

anyway... if you're interested, it's an open source project and can be
found at: http://valgrind.org/info/
 
J

James Kanze

How to find a STL class size, for example: string. I would like to
know what the size of the implementation of this class, I am not
interested in the size of its object but the class itself. There are
discussion regarding addition of all the data member of the class/
structure to find out its size, but is there a neat way to find out
class' size?

I'm afraid I don't understand the question: formally, only
objects have size, not classes. So do you want to know:

-- the actual size of the object: sizeof will give you that,
-- the total memory used by the object: this will depend
enormously on the implementation, and will probably vary
from one object to the next, or
-- the memory used by the class, independently of any
instances---this is also very, very implementation
dependent, and may also depend on which functions you use in
the class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,635
Latest member
SkyePurves

Latest Threads

Top