www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - A few suggestions about the auto keyword

First suggestion :
When reading D's specifications, I could not find wheter local objects declared
with the auto keyword get deallocated immediatly when the auto reference to it
goes out of scope.  Of course, I understand that the destructor get called
immediatly, but what about actual memory deallocation ? This question gave me an
idea : This could be an option. For I/O bound programs it would be preferable
that these objects get deallocated by the garbage collector when the program is
waithing for input.  For CPU bound programs (like games or real time
applications), it would be preferable that they get deallocated immediatly, thus
avoiding some gc scanning overhead and shortenig the undesirable pause that will
happen when the gc will kick in, most likely while the program is running.

Second suggestion :
Why limit auto references to local objects only ?  For many global references
and references owned by a class, it can be safely assumed that they are and will
remain the only non-circular reference to the referenced object, or that, at
least, all other non-circular references are guaranteed to stop referencing this
object before the first(auto) reference would.
For non local references, it could be legal to reassing an auto reference.  When
this would happen, the previously referenced object could be safely deleted
automaticaly.  This would increase performance for CPU bound programs, because
the gc would have less scanning for references to do.  Of course, the same
result can be achieved by staticaly allocating these objects, but if you forget
to use the delete operator, you would end up with a memory leak.
For auto references that are part of a class, the referenced object could be
deleted automatically not only when the reference is reassigned, but also when
the owning object itself get deleted.  There could be a restriction on
reassigning class owned auto references to avoid logical errors :  The new
referenced object must have been created by the same instance of the class that
will own it.  This way, it would prevent putting a reference to an object
created outside of the owning instance in an auto reference.  This could lead to
deleting the object prematurally if the auto reference is reassingned or the
owning object is deleted.
Oct 31 2004