On 23 July 2013 at 14:46, Steve Jaffe wrote:
| I agree that STL containers should be used whenever possible and new/delete 
avoided whenever possible.
| 
| However, there are times when explicit 'new' cannot be avoided (I'm now 
referring only to C++.) In those cases the best way to avoid the need for 
explicit memory management is to use an appropriate "smart pointer" such as 
boost::shared_ptr (std::shared_ptr as of C++11). Then one never has to 
explicitly call 'delete.'

And sometime you need some manual allocation (we do have that in a few places
inside the Rcpp code -- but it also deals with a C API).  But we agree: less
and less often, and ideally as little as possible.
 
| To clarify, though: what I said originally about NULL pointers applies to 
both C (malloc/free) and C++ (new/delete). 

Right, I agree and I once knew that too. I guess my habit just became to
assign NULL in order to have a 'flagged' value that can be tested for. And
yes, these days compilers are better and more forgiving. Still no excuse to
use pointers :)
 
Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to