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

How to design getter method for eigen-matrix efficiently

Tags: None
(comma "," separated)
wannamatrix
Registered Member
Posts
2
Karma
0
Hello,

in my project C++ i use some big Eigen-matrices (size: 8000x8000 ...) as global variable. Accordingly to data encapsulation principle in C++ i want to declare these matrices with private and use getter-methods for them. The methods should return reference or pointer to them. I dont have much experience with Eigen, so can anybody please tell me, how to do it efficiently ?

Should i also use smart pointers to manage the matrices or are they destroyed automatically without memory leak after going out of their scope in program ?

Thank you for any ideas for good design of C++ with Eigen library !
aluaces
Registered Member
Posts
13
Karma
0
OS
wannamatrix
Registered Member
Posts
2
Karma
0
No, that is different thing.

I have this class, where the matrices are declared and initialized:
Code: Select all
class Parameter {
public:
       // ...
       // getter for matrix R
   const MatrixXi & get_routing_matrix() const;
private:
       // ...
       // Matrix R as data member
   MatrixXi R;
};

// Implementation of getter R
const MatrixXi & Parameter::get_routing_matrix() const{
   return R;
}


I want to build a getter function for my matrix R, the getter function returns the reference to the initialized matrix R. My question is, is the above implementation okay and the most optimal for Eigen Matrix, or is there any better method ? We can use the pointer to the matrix, but then we need also to know the size of data block?


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]