By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,071 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,071 IT Pros & Developers. It's quick & easy.

How to find a STL class size?

P: n/a
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.

Oct 31 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
we*********@gmail.com wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 31 '07 #2

P: n/a
On 2007-10-31 19:26, we*********@gmail.com wrote:
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.

--
Erik Wikström
Oct 31 '07 #3

P: n/a
On Oct 31, 12:10 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-10-31 19:26, webinfin...@gmail.com wrote:
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.

--
Erik Wikström
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?

Oct 31 '07 #4

P: n/a
we*********@gmail.com wrote:
On Oct 31, 12:10 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
>On 2007-10-31 19:26, webinfin...@gmail.com wrote:
>>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.

--
Erik Wikström

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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 31 '07 #5

P: n/a
On Oct 31, 2:30 pm, "webinfin...@gmail.com" <webinfin...@gmail.com>
wrote:
On Oct 31, 12:10 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-10-31 19:26, webinfin...@gmail.com wrote:
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.
--
Erik Wikström

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/

Oct 31 '07 #6

P: n/a
On Oct 31, 7:26 pm, "webinfin...@gmail.com" <webinfin...@gmail.com>
wrote:
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.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Nov 1 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.