Boost logo

Boost Users :

From: Paul Giaccone (paulg_at_[hidden])
Date: 2007-04-17 13:35:29


Peter Dimov wrote:
> Paul Giaccone wrote:
>
>> Does anyone know of any evidence that the memory management in
>> smart_ptr might be incompatible with Maya, in particular, in gcc
>> 3.2.3?
>>
>> My supervisor, who is unfamiliar with Boost's smart_ptr library, but
>> is familiar with Maya, tells me that Maya has its own memory
>> management, and that Boost's smart pointers might somehow interfere
>> with this.
>>
>
> When you create a shared_ptr:
>
> shared_ptr<X> px( new X );
>
> and then destroy all of its copies, it behaves "as if" you've invoked
> "delete" at the same context where you created px. So if you've overloaded
> new and delete it will use them. I'm not sure how this applies to your
> particular case. My passing experience with the Maya SDK is that its classes
> are well behaved and manage their own memory, so there might be no need to
> use smart pointers.
>
Thanks. Of course, there is never any need to use smart pointers, but to
be clear, I'm using them for my own variables internal to the node, not
for the variables representing the input and output attributes that are
to be set from within Maya (specifically, from a MEL script). I have 2D
arrays and other more complex data structures, and using smart pointers
makes it much easier to manage these.

Here are some (disguised) extracts from my code:

1. The creator function, required by Maya. Note the absence of a smart
pointer. I tried wrapping this in a shared_ptr and returning .get() but
this caused a crash, if I remember rightly.

void* MyNode::creator(void)
{
    return new MyNode();
}

2. The destructor for MyNode:

~MyNode(void) { }

This is the one that bothers me.

All the input and output attributes that will be written to and read
from my MEL script are set up using Maya's generic MObject type. All the
other member data in MyNode needed for processing within the node that
are not of simple types (that is, all the members that are arrays or
more complex data structures) are created using smart pointers.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net