gNew
-
On 28/04/2013 at 20:01, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 12
Platform:
Language(s) : C++ ;---------
HelloThis maybe more of a C++ than C4D SDK question but gNew is from the SDK, so....
I use gNew to get a pointer to some memory for a buffer in a function. This function also populates the buffer. How long will that buffer be mine? Will it expire when I leave the function or stick around until it gets gDelete?
Right now I have the gNew in one function which gets called by another function where the gDelete is. And I know this is baaaad.
Peter
-
On 29/04/2013 at 05:57, xxxxxxxx wrote:
It's like new and delete. Every gNew requires a gDelete. You will get memory leaks if you do not free
the block of memory yourself. -
On 29/04/2013 at 06:48, xxxxxxxx wrote:
Actually to prevent memory leaks it is much much better to not call delete/gDelete manually.
It is much better to use Smart Pointers / RAII for this.
ge_autoptr.h has some Smart Pointers for C4D.
Unfortunately there are some problem with it that need to be fixed, not complicated if you know how but if not...If you are using C++11 then here are more Smart Pointers:
https://github.com/PluginCafe/Cinema-4D-Code-Collection/blob/master/C%2B%2B/Remo/AutoPointerPublic.hActually it should be work for old C++ too with some changes...