Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Allocating memory

 Post Reply Post Reply
Author
Message
WickedP View Drop Down
Member
Member
Avatar

Joined: 2011 Aug 21
Online Status: Offline
Posts: 458
Post Options Post Options   Quote WickedP Quote  Post ReplyReply Direct Link To This Post Topic: Allocating memory
    Posted: 2017 Sep 04 at 3:45am

User Information:

Cinema 4D Version:   R14 
Platform:   Windows  ;   
Language(s):     C++  ;   

---------

Hi Folks,

looking for some clarification on allocating and deallocating memory.

When should an ObjectData inherited class destroy its data? Should this be done in the destructor, or should I be overriding Free()? Something else?

Similar question for the constructor. In my custom classes I set all pointers to nullptr in the constructor, and usually allocate the memory elsewhere (I setup my own initialiser functions). But in my ObjectData plugins I do this in the constructor. Should I be doing this in the Init() function? I read a post here from a few years a go that said the Init() might be called more than once - why might this happen? And should I therefore be setting up tests inside the Init() function?

WP.

Edit - spelling error!


Edited by WickedP - 2017 Sep 05 at 12:28am
WickedP® Developer
http://www.wickedp.com
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1482
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Sep 05 at 7:45am
Hi WP,

while you technically can use constructor and destructor for such purposes, we strongly recommend not to do so. Rather use Init() and Free(). The reason is the return value of Init(), so other parts of Cinema can react to for example allocation failures and an object not initializing correctly thereof.


Init() may indeed be called several times for example for object instances on the undo stack (while not being the exact same instances, they still somewhat refer to the same object). If this causes problems for your implementation you will need to handle this yourself. See also the manual on the Undo System.

Cheers,
Andreas
SDK Support Engineer
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.