Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#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 14 years ago by Peter

Status: newassigned

comment:3 Changed 14 years ago by Peter

Resolution: fixed
Status: assignedclosed

(In [640]) fixes #132 and #95, and refs #135 replaced bool owner in DataLookup2D with ref_count u_int*. When the DataLookup2D does not own underlying data ref_count=NULL otherwise it points to a u_int telling how many owner there are of the data. When the counter reaches zero the data is deleted.

comment:4 Changed 14 years ago by Jari Häkkinen

Milestone: later0.3 (Public release)
Note: See TracTickets for help on using tickets.