This is the mail archive of the
mailing list for the GCC project.
Proposed C++ extension
- From: "Niall Douglas" <ned at nedprod dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sat, 31 Aug 2002 01:27:20 +0200
- Subject: Proposed C++ extension
Firstly, I'll apologise for not diving deep and producing a patch for
g++. Last time I tried, I got very very lost ...
My suggestion is adding support for temporary object copy
constructors - these differ from normal copy constructors in that
when the object is being created by the compiler rather than the
user, the temporary object copy constructor is called instead.
Why? Because C++ doesn't support multithreading very well. I have a
number of implicitly shared classes for which I had to disable
implicit sharing because of the potential of data corruption as it's
impossible to synchronise all users of the implicit data without
running through a mutex each time.
Unfortunately disabling implicit sharing creates performance problems
in something like a string class. If we had a special copy
constructor for temporary objects, we could do ptr copies for the
temporary objects and the real copy constructor for the final object.
Obviously, optimisation can decide when user created local objects
are unnecessary, and hence optimise them into temporary land.
Anyway, if you were to add this, I'd stick the appropriate code into
my implicitly shared-disabled classes. So would others I'm sure.
String work would become much quicker.
The other suggestion is a precall and postcall handler whereby in
every call to an object, the compiler wraps the call with the precall
and postcall code. Again, it's use is for porting old code to become
multithreading aware - but I can envisage other useful uses as well.
Anyway, those are my experiences from learning C++. I'm well into
year three of learning it, but I'm still nowhere close to done!