#95 closed enhancement (fixed)
ownership in Lookups is not optimal
Reported by: | Peter | Owned by: | Peter |
---|---|---|---|
Priority: | major | Milestone: | yat 0.3 (Public release) |
Component: | classifier | Version: | |
Keywords: | Cc: |
Description
Say we have a MatrixLookup? ml and we create a new MatrixLookup? using the copy constructor:
MatrixLookup? ml2(ml);
then is ml2 independent of ml in the sense that calling operator() does look via ml but directly into underlying matrix. Also if ml goes out of scope ml2 is well defined and everything works fine. However, if ml is owner of the underlying matrix, ml will delete the matrix in its destructor and everything is not perfectly fine anymore. At least not for ml2 that is pointing to a deleted object.
The simple solution here is of course to just say that this is the way it is and be very clear about this in documentation. Are we?
A better solution would be to introduce some kind of ownership counter in MatrixLookup?. So when Lookups own their data add one to the counter in copy constructors (and assignment) and subtract one in destructors (and assignment). And only delete underlying object in destructor when counter reaches zero.
Change History (4)
comment:1 Changed 16 years ago by
Status: | new → assigned |
---|
comment:2 Changed 16 years ago by
comment:3 Changed 16 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:4 Changed 16 years ago by
Milestone: | later → 0.3 (Public release) |
---|
see article by Andrei Alexandrescu.
http://www.awprofessional.com/articles/article.asp?p=31529&seqNum=5&rl=1