467,864 Members | 1,807 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,864 developers. It's quick & easy.

Does a ctor/dtor occupy memory

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
  • viewed: 1371
Share:
1 Reply

"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.

Similar topics

2 posts views Thread by Eric Liu | last post: by
10 posts views Thread by richardclay09 | last post: by
7 posts views Thread by Thomas | last post: by
6 posts views Thread by puzzlecracker | last post: by
6 posts views Thread by junw2000 | last post: by
5 posts views Thread by mkaushik | last post: by
8 posts views Thread by Grizlyk | last post: by
5 posts views Thread by peifeng_w | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.