which design is better to wrap another class instance

Discussion in 'C Programming' started by George2, Apr 12, 2008.

  1. George2

    George2

    Joined:
    Feb 12, 2008
    Messages:
    108
    Hello everyone,


    Some people doubt that the design below is inferior compared to design which makes f, either Foo* or Foo&. The reason is below design will waste memory space and degrade performance by creating a new instance.

    I think it depends. If we really needs to wrap a new instance, I think the following design is fine. If we needs to refers to an existing instance, this design is inferior because it will waste memory space and degrade performance by creating a new instance and destroy the original one.

    Code:
    class Foo;
    
    class Goo
    {
        Foo f; // change to Foo* pf or Foo& rf is always better?
    }
    

    thanks in advance,
    George
    George2, Apr 12, 2008
    #1
    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. Aaron Fude

    To wrap or not to wrap?

    Aaron Fude, May 8, 2008, in forum: Java
    Replies:
    12
    Views:
    680
    Chronic Philharmonic
    May 10, 2008
  2. Martin P. Hellwig
    Replies:
    1
    Views:
    362
    Martin P. Hellwig
    Mar 26, 2010
  3. Raj Singh
    Replies:
    2
    Views:
    185
    Rick DeNatale
    May 29, 2008
  4. Art Werschulz

    Text::Wrap::wrap difference

    Art Werschulz, Sep 22, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    214
    Art Werschulz
    Sep 22, 2003
  5. Art Werschulz

    Text::Wrap::wrap difference

    Art Werschulz, Sep 24, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    230
    Anno Siegel
    Sep 25, 2003
Loading...

Share This Page