[C++] returing object from functions
From: Spacen Jasset (a_at_b.com)
Date: 09/26/04
- Next message: Val: "ios::failbit always true"
- Previous message: Spacen Jasset: "Re: Random numbers with no duplicates"
- Next in thread: Jacques Labuschagne: "Re: [C++] returing object from functions"
- Reply: Jacques Labuschagne: "Re: [C++] returing object from functions"
- Reply: Niklas Borson: "Re: [C++] returing object from functions"
- Reply: Alwyn: "Re: [C++] returing object from functions"
- Reply: Jerry Coffin: "Re: [C++] returing object from functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 26 Sep 2004 01:12:08 +0100
Suppose I have a function
ParsedObject parse( const string &s )
{
ParsedObject p;
...
return p;
}
The function parses a string, and fills p full of useful information. p is
also quite a large object. On return then, the compiler must invoke p's copy
constructor since I've defined one ( and not taken the default )
This must surely be quite inefficient, since the copy constructor must be
called, and the compiler can't easily optimise this since my copy
constructor may do some fancy things like reference counting, data sharing
or the like.
Isn't:
parse( ParsedObject &p, const string &s ) always a better method, since no
copy is necessary?
- Next message: Val: "ios::failbit always true"
- Previous message: Spacen Jasset: "Re: Random numbers with no duplicates"
- Next in thread: Jacques Labuschagne: "Re: [C++] returing object from functions"
- Reply: Jacques Labuschagne: "Re: [C++] returing object from functions"
- Reply: Niklas Borson: "Re: [C++] returing object from functions"
- Reply: Alwyn: "Re: [C++] returing object from functions"
- Reply: Jerry Coffin: "Re: [C++] returing object from functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]