pingus-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cleanup patch / design rules


From: Ingo Ruhnke
Subject: Re: cleanup patch / design rules
Date: 26 Aug 2002 13:05:04 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

David Philippi <address@hidden> writes:

>> That might work in a few cases, but in general references are to
>> inflexible (no null element, no way to reset them, etc.), so I avoid
>> them mostly in classes.
> 
> That a reference always points to something is considerd to be one of it's 
> greatest advantages.

Well, and its actually not true.

{
  Bla* obj = new Bla;
  Bla& ref_obj = *obj;
  delete obj;
  ref_obj.bla();
  // crash...
}

References in C++ are quite an obscure concept, they should probally
have called them aliases, since thats what they really are.

And there is always the problems that References and STL don't mix
well.

> As long as we don't want to rewrite large parts of Pingus it may be
> neccessary to use some dummy objects as initializers / 0 replacement
> for caching references, but caching pointers which are not always
> initialized should be moved into the methods anyway IMHO.

References for parent/child relation ships which arn't meant to get
reset are ok. But for everything else that needs a 0, pointers are far
easier to use.

>> We should probally add some wrappers around new/delete to make it
>> easier to track them and to add some bookkeeping to catch double
>> deletes, etc.
> 
> What new and delete do you mean? The global ones? operator new/delete?

Yep.

> The array variants?

We don't use the array variants, where we need arrays we use
std::vector.

> There's a bit more to cover than one may think
> at first glance. I consider changing the behaviour of new and delete
> very dangerous since one doesn't expect them to be overloaded.

I don't consider to overload them, that would be to obscure, but just
to wrapp them with some functions. Something like this:

template<class T> 
T* myNew()
{
        return new T();
}

template<class T> 
void myDelete(T* data)
{
        delete data;
}

-- 
ICQ: 59461927                                    http://pingus.seul.org | 
Ingo Ruhnke <address@hidden>           http://pingus.seul.org/~grumbel/ |
------------------------------------------------------------------------'




reply via email to

[Prev in Thread] Current Thread [Next in Thread]