copy constructors hurting performance
From: Shea Martin (smartin_at_arcis.com)
Date: 11/04/03
- Next message: Alfred E Neuman: "AClass ac=AClass("name",23); VS. AClass ac("name", 23);"
- Previous message: agent mike: "word count"
- Next in thread: Ron Natalie: "Re: copy constructors hurting performance"
- Reply: Ron Natalie: "Re: copy constructors hurting performance"
- Reply: Victor Bazarov: "Re: copy constructors hurting performance"
- Reply: David Rubin: "Re: copy constructors hurting performance"
- Reply: Cagdas Ozgenc: "Re: copy constructors hurting performance"
- Reply: lilburne: "Re: copy constructors hurting performance"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 04 Nov 2003 09:52:38 -0700
I have a String class (I know I am re-inventing the wheel, yes I have
heard of boost, and of QString).
My copy constructor does a deep (strcpy) of the char *_buffer member.
I have a member function func(const String ¶m). When an actual
String is passed as the param this is nice and efficient.
I have a constructor which takes a const char* as an argument. And
performs a deep copy of the const char *buffer.
The issue occurrs when I make the following call:
func("this is the param");
The String(const char *buf) constructor is called, making a deep copy of
the data. Because func takes a const arg, it will never alter the
buffer, thus the deep copy of the const char * is needless, and could be
expensive.
Does anyone see an easy and somewhat safe design, to avoid the needless
copy's? Or is the only way to overload the methods to take a const
char* as well?
I think I already know the answer to this, but I would rather be safe
that sorry.
Thanks,
~S
- Next message: Alfred E Neuman: "AClass ac=AClass("name",23); VS. AClass ac("name", 23);"
- Previous message: agent mike: "word count"
- Next in thread: Ron Natalie: "Re: copy constructors hurting performance"
- Reply: Ron Natalie: "Re: copy constructors hurting performance"
- Reply: Victor Bazarov: "Re: copy constructors hurting performance"
- Reply: David Rubin: "Re: copy constructors hurting performance"
- Reply: Cagdas Ozgenc: "Re: copy constructors hurting performance"
- Reply: lilburne: "Re: copy constructors hurting performance"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|