CoreLinux++
|
Goals
|
Developer's Corner
|
Contacts
|
|
CoreLinux++ SmartPointer Draft 0.3
==================================
A SmartPointer is a lightweight proxy that substitutes itself for a
object instance until which point access requires said instance to be
instantiated.
A base SmartPointer should:
---------------------------
* Be thread safe. (Synchronized object)
* Survive instance type queries (casting, testing, etc.). Templated class
* Be independent of faulting in the underlying instance. Templated methods
with default implementations.
* Default to heap based instantiation
An immediate derivation for the core library:
---------------------------------------------
* Contain reference counting and instrumentation.
An immediate derivation for the framework extensions:
-----------------------------------------------------
* Have identity. I believe this to be neccessary for persistence and faulting capability.
SnartPointer Pros
-----------------
* Less memory required.
* Reduced heap fragmentation (with factory and/or heap managed instantiation).
* More scalable
SmartPointer Cons
-----------------
* Require a less natural way of object referencing:
(*SmartPointerPtr)->instanceOperation(...)
* Require pervasive and strict management of references for example:
Assuming that the underlying iterator increments the reference count
for( iterator aItr=...;
aItr->isValid();
aItr->setNext() )
{
SmartPointerPtr aObject( aItr->getElement() );
(*aObject)->doSomething(...);
}
would leak reference, unless it was something like:.
for( iterator aItr=...;
aItr->isValid();
aItr->setNext() )
{
SmartPointerPtr aObject( aItr->getElement() );
(*aObject)->doSomething(...);
aItr->returnElement( aObject );
}
Issues
------
* There is a knee of the curve extension by using SmartPointers instead
of resident instances. But, it just moves the knee further out.
* Once the instance is instantiated, the SmartPointer goes away? My
experience has been that the solution space assumes constant use of the
smart pointer as proxy to instance.
Copyright © 1999, 2000 by CoreLinux Consortium
This material may be distributed only subject to the terms and conditions set forth in the
Open Publication License
|
|
|