On 3/3/18 9:10 PM, Chris Angelico wrote:
On Sun, Mar 4, 2018 at 1:01 PM, Ooomzay <ooom...@gmail.com> wrote:
On Saturday, 3 March 2018 17:44:08 UTC, Chris Angelico wrote:
On Sun, Mar 4, 2018 at 4:37 AM, Richard Damon <rich...@damon-family.org>
Yes, stack allocated object in C++ have a nice lifetime to allow RAII to
work, but it doesn't just work with stack allocated objects. A lot of RAII
objects are members of a class object that may well be allocated on the
heap, and RAII makes sure that all the needed cleanup gets done when that
object gets destroyed.
How do you guarantee that the heap object is properly disposed of when
you're done with it? Your RAII object depends 100% on the destruction
of the heap object.
Smart pointers (unique_ptr and friends) are used to manage heap object
lifecycles n . These are analogous to python object references.
Yep, cool. Now do that with all of your smart pointers being on the
heap too. You are not allowed to use ANY stack objects. ANY. Got it?
ChrisA
Now write your Python without using anything not on the heap either (so
no binding your objects to a name).
As Chris said, the stack variables in C++ are the local names used to
refer to the objects.
--
Richard Damon
--
https://mail.python.org/mailman/listinfo/python-list