Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualATC

Posted 10 October 2012 - 03:14 PM

I'd actually suggest smart pointers.


I second that. You can use reference counting to destroy object instances when nothing holds a reference an object any longer. You can also hook up your reference count system so that the count is decremented when a smart-pointer falls out of scope... the result: automatic disposal. If you're up for a challenge and know what you're doing you can even override C++'s new and delete operators so that you can allocate all objects to a custom, managed heap; but you will need to implement heap defragmentation, optimized memory copy/move algorithms and quite a few other things. I can be done but is hard... however, the end-result can be a spectacular and efficient memory management system.

Just to demonstrate what I'm talking about:

[source lang="cpp"]void f(){ SmartPtr<Model> pCarModel = somePtr; // do stuff with the car model... pCarModel->ReleaseRef( );}[/source]

#2ATC

Posted 10 October 2012 - 03:11 PM

I'd actually suggest smart pointers.


I second that. You can use reference counting to destroy object instances when nothing holds a reference an object any longer. You can also hook up your reference count system so that the count is decremented when a local object falls out of scope. If you're up for a challenge and know what you're doing you can even override C++'s new and delete operators so that you can allocate all objects to a custom, managed heap; but you will need to implement heap defragmentation, optimized memory copy/move algorithms and quite a few other things. I can be done but is hard... however, the end-result can be a spectacular and efficient memory management system.

#1ATC

Posted 10 October 2012 - 03:11 PM

I'd actually suggest smart pointers.


I second that. You can use reference counting to destroy object instances when nothing holds a reference an object any longer. You can also hook up your reference count system so that the count is decremented when a local object falls out of scope. If you're up for a challenge and know what you're doing you can even override C++'s new and delete operators so that you can allocate all objects to a custom, managed heap; but you will need to implement heap defragmentation, optimized memory copy/move algorithms and quite a few other things. I can be done but the end-result can be a spectacular and efficient memory management system.

PARTNERS