← Back to team overview

dolfin team mailing list archive

Re: Use of Array<type> class (in assembly)

 

On Wednesday January 25 2012 20:04:05 Joachim Berdal Haga wrote:
> > I am pretty sure the shared_array object were added as a simple way of
> > deciding ownership of the data. If the creation of the shared_array is
> > costly we could use a ownership flag instead.
> 
> Or maybe two different classes. The thing is, ownership of Array<>
> data is not known: if it's created with the (uint,T*) constructor then
> the contents will be deleted by whoever owns the T*, and it's not safe
> to hold references to it. Or so it seems to me.

You can say that, but mixing C-api and Python we already have that situation 
several other places. The point is that when the (uint,T*) constructor is used 
Array<> should not take ownership of the data. We could also change the 
pointer to a shared_ptr and use a special function for the deleter, which 
calls delete [] instead of the default delete. That might be less expensive. 

But with Array<> I suggest we go with a flag type of memory management, as we 
need something that is fast. 

> But yes, it's fairly costly.

You can always try changing the internal storage to just a T* and setting a 
flag for ownership, and check if there are any places where 
boost::shared_array<T> is used.

Johan


References