This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Eigen, copy constructor and memory policy

Tags: None
(comma "," separated)
poulejapon
Registered Member
Posts
6
Karma
0
OS
When I copy an array B to an array A via A=B, does Eigen operate a copy, or will they share the data as long as only const members are accessed?

More generally where can I find information about the memory sharing policy in the documentation?
Hauke
Registered Member
Posts
109
Karma
3
OS
Hi poulejapon,

poulejapon wrote:When I copy an array B to an array A via A=B, does Eigen operate a copy, or will they share the data as long as only const members are accessed?

More generally where can I find information about the memory sharing policy in the documentation?


The data is copied right away, i.e. we are not using any COW (copy-on-write) policy. That is pretty much all there is to say regarding any sharing policy because sharing does simply not exist.

Somewhat related to sharing is the memory mapping with Eigen::Map, see also here: http://eigen.tuxfamily.org/dox-devel/Qu ... ickRef_Map

In general, in case one wants to share large objects in different modules in a library, I would go for shared_ptr. This applies of course only to heap allocated matrices because for stack objects sharing in this way does not make any sense because one would basically move the matrix to the heap by wrapping it in a shared_ptr. There, your only chance are references.

Regards,
- Hauke
poulejapon
Registered Member
Posts
6
Karma
0
OS
thank you very much. That helped a lot.


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]