<p>Thank you Dirk for the quick response;<br>
and for noting the memory handling. </p>
<p>I am aware of it and there are other ways of obtaining a pointer to some memory location. I used malloc/free to put focus on arma::mat copying data during assignment and/or not able to use reference as class member. <br>
Leaving plenty of room for that I am doing it wrong and there is a way to initialize a class member arma::mat with external ptr.<br>
<br>
The documentation tells about arma::mat behaviour when setting ..., false, strict=true); in my interpretation the last argument prevents changing size of arma::mat resulting in a 'copy free' instance. The provided c++ only example demonstrates that; it works as documented.</p>
<p>What I am looking for is setter on arma::mat to flexibly point to some memory location or a different '=' operator in terms of handling arma::mat objects when initialized with external pointer.</p>
<p>It is an armadillo question but came accross your post on stackoverflow where you suggested someone with similar question to post here.</p>
<p>Bigmemory looks great; but the point here is to able to use matlab like BLAS level 3 operations on some large vector; small segements at a time. </p>
<p>We use HDF5 for large datastores with flexible STL container like interface.</p>
<p>Thanks again,<br>
Steven<br>
</p>
<div class="gmail_quote">On Nov 25, 2013 10:28 PM, "Dirk Eddelbuettel" <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Steven,<br>
<br>
In a case like this I would try to set up a fist minimal working example<br>
using just plain C++, and no R. Once that works, try it with R.<br>
<br>
For Armadillo, the docs at <a href="http://arma.sourceforge.net/docs.html#Mat" target="_blank">http://arma.sourceforge.net/docs.html#Mat</a> are your<br>
best shot. I presume you saw what it says about strict=true. Also, in<br>
<br>
double* p = static_cast<double*>( malloc( 30*sizeof(double) ));<br>
arma::mat M(p, 3,10, false, true ); // this works nicely<br>
<br>
you are going against the "Writing R Extensions" rule of mixing system<br>
malloc/free with R. That is generally a bad idea.<br>
<br>
If your intent is to keep memory 'fixed' and outside of R, you can use<br>
Bigmemory objects via external pointers (Rcpp::XPtr). This may be of<br>
interest: <a href="http://gallery.rcpp.org/articles/using-bigmemory-with-rcpp/" target="_blank">http://gallery.rcpp.org/articles/using-bigmemory-with-rcpp/</a><br>
<br>
That should extend to wrapping Armadillo around such memory. After all,<br>
Armadillo behaves just _great_ with the R-allocated objects we pass back and<br>
forth.<br>
<br>
Hope this helps, Dirk<br>
<br>
--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</blockquote></div>