Overhead

Discussion in 'C++' started by Garma, Jan 16, 2004.

  1. Garma

    Garma Guest

    When define member like "string" type for a class, we can either define it
    as "char *" or "string." I don't know which one should be better. My
    concern is that "string" has some "overhead" though its usage is so
    convenient. Additionally 'string' member could be needed to pass into a
    function which expect a variable of 'char *' Then the function call could
    make the code looks like,

    function(TheObject.PassMeTheStringMember().c_str(), 12, ...);

    This is not that readable to me. I want to hear your opinion about this.


    Another question is related to using STL. There are two classes, A and B:

    class A
    {
    private:
    list<Class B>InnerList;
    ....
    };

    class A contains a STL list. Could objects of type class A be put in
    another std::list, OuterList (you see an iteration here)? Could it be put
    in other type of container?

    Thanks for your comments!
    Garma, Jan 16, 2004
    #1
    1. Advertising

  2. In article <E6HNb.44687$>, Garma wrote:
    > When define member like "string" type for a class, we can either define it
    > as "char *" or "string." I don't know which one should be better. My


    You need to manage the memory somehow. It is usually better to avoid managing
    multiple dynamic memory allocations within the one class (causes all sorts
    of problems with exception safety, and makes code less clean). So you would
    probably need to use *some* sort of class to manage the storage anyway.

    > concern is that "string" has some "overhead" though its usage is so
    > convenient.


    What type of overhead ? Is this "overhead" causing any problems in your code ?

    > Additionally 'string' member could be needed to pass into a
    > function which expect a variable of 'char *' Then the function call could
    > make the code looks like,
    >
    > function(TheObject.PassMeTheStringMember().c_str(), 12, ...);
    >
    > This is not that readable to me. I want to hear your opinion about this.


    In my opinion, it's readable (but it would be more so if you used shorter names
    for your member functions!)

    > Another question is related to using STL. There are two classes, A and B:
    >
    > class A
    > {
    > private:
    > list<Class B>InnerList;
    > ...
    > };
    >
    > class A contains a STL list. Could objects of type class A be put in
    > another std::list, OuterList (you see an iteration here)?


    Yes

    > Could it be put in other type of container?


    Yes

    Cheers,
    --
    Donovan Rebbechi
    http://pegasus.rutgers.edu/~elflord/
    Donovan Rebbechi, Jan 16, 2004
    #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. John T. Goodman

    Overhead of 4-port over 2-port SRAM

    John T. Goodman, Jan 25, 2005, in forum: VHDL
    Replies:
    0
    Views:
    587
    John T. Goodman
    Jan 25, 2005
  2. Showjumper

    Does Option Strict On add overhead?

    Showjumper, Jul 31, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    351
    John Saunders
    Jul 31, 2003
  3. Brett Robichaud

    Trace overhead

    Brett Robichaud, May 5, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    489
    Brett Robichaud
    May 6, 2004
  4. Dave Williamson
    Replies:
    2
    Views:
    445
    Rocky Moore
    Aug 15, 2004
  5. tony
    Replies:
    1
    Views:
    336
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Jan 19, 2005
Loading...

Share This Page