Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    gNew

    SDK Help
    0
    3
    302
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 28/04/2013 at 20:01, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   12 
      Platform:      
      Language(s) :     C++  ;

      ---------
      Hello

      This 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

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          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.h

          Actually it should be work for old C++ too with some changes...

          1 Reply Last reply Reply Quote 0
          • First post
            Last post