Registered Member
|
I have a program in which I would like to define types in the following manner:
etc. where J, N, and similar constants are generally < 700 and known at compile-time. The largest matrix would be about 700 x 25. The program was causing a stack overflow (compiled for Windows XP (32-bit) with VisualStudio 2010), which led me to this page: http://eigen.tuxfamily.org/dox/TutorialMatrixClass.html#TutorialMatrixDynamic
Realizing I needed to force these types to be created on the heap, but also considering I would like to have some record of their intended size at compile time, led me to define the following:
This solved the problem of the stack overflow, but I've subsequently extended the code, and now I'm running into the same problem again. According to http://eigen.tuxfamily.org/dox/TutorialMatrixClass.html#TutorialMatrixOptTemplParams,
My question is this: does Eigen always pre-allocate space on the stack for matrices defined with Max<Cols/Rows>AtCompileTime, or does it only do so for smaller matrices (i.e. according to some optimization rule)? Is there some secret to defining a matrix such that: (1) rows and/or cols are set to constant values at compile time, and (2) space for the matrix is always allocated dynamically from the heap? |
Moderator
|
The Max<Cols/Rows>AtCompileTime are precisely to avoid heap allocation by enforcing stack allocation even for matrices with runtime sizes. What you want is exactly the opposite, however this is not supported by Eigen::Matrix. Why do you need to know the size at compile time? For such large matrices there is really no advantage.
|
Registered Member
|
Thank you for the clarification, that's what I was hoping to understand. As for why I would want to set the size at compile time, I have found that doing so helps me avoid some hard-to-spot coding errors and has proved helpful in keeping my code more readable. Thanks again for the quick and helpful reply.
|
Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]