Re: [eigen] Eigen with Boost::smart_ptr

[ Thread Index | Date Index | More Archives ]

On 11/08/2011 08:44 AM, Christoph Hertzberg wrote:

On 08.11.2011 13:07, Sathishkumar Duraisamy wrote:
Hi all,

I am in some kind of signal processing application. To manage and
manipulate data, I have been using Eigen Matrix.

Can you please give me some recommendation for using pointers for
dynamically allocated eigen matrix?

I guess you need to be a bit more specific for that ...
Maybe you don't need to dynamically allocate your matrices at all, since
Eigen::MatrixXd already dynamically allocate their memory.

Side note: That might actually be a nice feature, having kind-of a
shared matrix, i.e. multiple instances of the same matrix share the same
memory until the matrix is modified, in which case it allocates new
memory (unless of course it is the last instance using that memory).

I've actually been working on shared Eigen matrices as part of an Eigen interface to another project, and I'd be happy to contribute code to that effect, but it's not as straightforward as one might expect. For instance, when one gets a block of a shared matrix, does the block share memory with the original? That would make it a lot harder for the compiler to optimize away the block, but it would make it a lot more sensible when you want to return the block from a function where the matrix is a local variable.

Is it possible to use boost::smart_ptr and boost::pointer_container
with Eigen Matrix. In case, which is good smart_ptr, shared_ptr or
week ptr?

I can't see a reason why it is not possible.

smart_ptr is just the name of the library, isn't it?
W.r.t shared_ptr vs weak_ptr: you can construct weak_ptr only from
shared_ptr, so you need at least one shared_ptr per matrix anyways.
What's better afterwards depends on what you are planning to do.

I agree, and I'd also say that I can think of very few situations in which one would gain anything by using pointer container with Eigen, though it is possible. Pointer container is mainly intended for holding hierarchies of polymorphic classes.


Mail converted by MHonArc 2.6.19+