[xsde-users] Using auto_ptr for passing shared objects

Boris Kolpackov boris at codesynthesis.com
Mon Nov 23 08:46:43 EST 2015


Hi Andrey,

Andrey Filimonov <andrey.v.filimonov at gmail.com> writes:

> With XSDe i have raw pointers, thus i have to define who is responsible for
> creating and destroying objects. Adapting semantic layer to XSDe may be
> tricky because object ownership isn't obvious at all. In the code not
> taking care of object lifecycle it's hard to figure out who is owning and
> who is responsible for what.

This is not quite correct. While it may not be obvious from the C++/Hybrid
object model interface who owns what (unlike if we used auto_ptr), this is
all very well defined in the C++/Hybrid Getting Strated Guide, specically,
Section 4.2, "Memory Management". In particular, the object model owns its
sub-nodes (just like in C++/Tree). Also, nothing prevents you from owning
the whole object model with auto_ptr (in fact, quite a few XSD/e examples
do exactly that). You can also "detach" sub-nodes from the object model and
manage them with auto_ptr just like in C++/Tree (see --generate-detach).
And if you need to attach the node back to the object model, simply use
auto_ptr::release() (this is probably the only situation where you have
to do a little bit more than in C++/Tree).


> 2) if possible make code generated by XSDe rely on auto_ptr instead of raw
> pointers to let current implementation of semantic layer keep its fuzzy
> ownership.
> 
> Option 2 seem to cost much less, but from your last message i understood
> that sharing objects the way can be done with XSD [...]

I am not sure what "sharing" you refer to here. With auto_ptr you can
only transfer ownership (which is supported in both XSD and XSD/e).

Boris



More information about the xsde-users mailing list