On Sat, 27 Sep 2003 17:08:37 +0200 (Romance Daylight Time) Vadim Zeitlin
<[EMAIL PROTECTED]> wrote:

> On Sat, 27 Sep 2003 16:12:49 +0200 (CEST) Robert Vazan <[EMAIL PROTECTED]> wrote:
> 
>  In fact, we do have smart pointers :-) Look at MObject.h and
> DECLARE_AUTOPTR_XXX() macros.

These macros cannot be used in headers, but many pointers are member
variables. I would need to make some changes to make this possible, but
still the shortest declaration that can be used in header is four lines
long.

#ifndef AUTOPTR_Profile
#define AUTOPTR_Profile
DECLARE_AUTOPTR(Profile)
#endif

This is because X_obj is class and it must be defined only once. Plus it
would be necessary to DEFINE_AUTOPTR in one file to work around forward
declarations. If templates were used, the #ifndef...#endif wrapping would
be unnecessary.

> True, not all the code uses them and we don't
> have a clear convention for the functions returning a pointer (they should
> return an auto ptr instead...).

Simplest solution is to make return values the same type as members and
locals. Separate type could transfer ownership to save some IncRef/DecRef
pairs. Parameters can be bare pointers, because there is no way to destroy
source smart pointer without recursion.

So changes that I would want to make are (a) use templates, (b) allow
forward declarations, and (c) use separate type for return values. Only (b)
is essential to make smart pointers useful, but (a) and (c) make it better.

> For (1) we could try using templates instead but I'd like to see the
> comparison of compiling time after replacing MObject.h macros with
> templates.

Gcc eats 100-1000 cycles per byte of code, including headers. I think it
has different performance problems than template instantiation.



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Mahogany-Developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-developers

Reply via email to