Does a ctor/dtor occupy memory

Discussion in 'C++' started by pmastroianni, Apr 1, 2005.

  1. pmastroianni

    pmastroianni Guest

    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?
     
    pmastroianni, Apr 1, 2005
    #1
    1. Advertising

  2. pmastroianni

    Howard Guest

    "pmastroianni" <> wrote in message
    news:...
    > 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
     
    Howard, Apr 1, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacques Labuschagne

    Explicit ctor/dtor calls

    Jacques Labuschagne, Jul 20, 2003, in forum: C++
    Replies:
    3
    Views:
    346
    Michael Kochetkov
    Jul 20, 2003
  2. Karl Heinz Buchegger

    Ctor/Dtor order

    Karl Heinz Buchegger, Jul 30, 2003, in forum: C++
    Replies:
    3
    Views:
    1,235
    Greg Comeau
    Jul 30, 2003
  3. Grizlyk
    Replies:
    8
    Views:
    489
    Grizlyk
    Nov 29, 2006
  4. Replies:
    5
    Views:
    394
    Kai-Uwe Bux
    Nov 29, 2006
  5. , India
    Replies:
    2
    Views:
    314
    Stefan Ram
    Mar 30, 2010
Loading...

Share This Page