[Libxmlplusplus-general] Node ownership
- From: murrayc t-online de (Murray Cumming)
- To: libxml++ <libxmlplusplus-general lists sourceforge net>
- Subject: [Libxmlplusplus-general] Node ownership
- Date: 06 Feb 2003 16:58:39 +0100
On Tue, 2003-02-04 at 08:21, Stefan Seefeld wrote:
> * decide who can create Nodes,
Clearly libxml++ objects need to be able to create nodes. Maybe people
want to create nodes with normal C++ memory management too.
> who owns them if they are taken out of a document,
At the moment they are deleted if that happens.
> etc. May be a 'Store' object may help...
So, let's list some possible solutions. For instance,
1. A boolean owned_by_libxml member variable.
The libxml destroy callback would not destroy the C++ wrapper instance
if owned_by_libxml is false.
Methods such as Node::add_child_node(Node*) would set the
owned_by_libxml to true and take ownership. This would be documented.
Methods such as Node::remove_and_detach() would set the
owned_by_libxml and the Node should be deleted if it is never added to
something else with add_child_node().
2. Use of shared-reference-counting smartpointers everywhere.
The libxml destroy callback would just unref() the C++ wrapper
instance. It would be destroyed when the last smartpointer instance went
out of scope.
I like this idea (I liked it when Xerces-C++ used it in the past), but
- there might be complex circular-references issues, and
- people might think it's slow or takes extra memory.
3. Implement reference-counting, as above, but make use of smartpointers
optional. Smartpointers would be necessary when copying parts of an XML
tree to another tree.
--
Murray Cumming
murray usa net
www.murrayc.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]