Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Does a ctor/dtor occupy memory

Reply
Thread Tools

Does a ctor/dtor occupy memory

 
 
pmastroianni
Guest
Posts: n/a
 
      04-01-2005
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?
 
Reply With Quote
 
 
 
 
Howard
Guest
Posts: n/a
 
      04-01-2005

"pmastroianni" <> wrote in message
news: 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS for a Link to Occupy the Whole Cell vunet.us@gmail.com HTML 11 06-14-2007 08:22 AM
Does "float" always occupy 32 bits chandanlinster C Programming 16 09-07-2006 11:48 PM
how much memory does an empty STL deque occupy? R.Z. C++ 9 09-20-2005 11:24 PM
Why does 20 lines of text occupy 1 megabyte? Alasdair Baxter Computer Support 9 05-11-2005 11:01 PM
Differences between Sony Memory Stick & memory Stick Pro vs Memory Stick Duo? zxcvar Digital Photography 3 11-28-2004 10:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57