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

Does a ctor/dtor occupy memory

P: n/a
When a class is instantiated, will the ctor and dtor occupy memory?
IF ctor and dtor do occupy memory of an instantiated class where would
they be in memeory?
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"pmastroianni" <pm**********@shelbrook.com> wrote in message
news:70**************************@posting.google.c om...
When a class is instantiated, will the ctor and dtor occupy memory?
IF ctor and dtor do occupy memory of an instantiated class where would
they be in memeory?


A good book should tell you this.

Member functions, including the constructor and destructor, obviously have
to exist "somewhere" (unless, I suppose, they do nothing, in which case an
optimizing compiler could remove them). Where they exists is entirely up to
the compiler and the operating system.

But member functions exist on a "per class" basis, not a "per instance"
basis. There's no reason to have copies of those functions lying around for
every instance of the class that your code creates. Each instance simply
refers to the same set of member functions.

Member data, obviously, needs to exist for every instance, because the
member variables likely take on different values for each instance. (At
least for non-static member data, that is.) But the functions are just sets
of instructions, and don't need separate copies.

-Howard
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.