I have downloaded Xerces source code
and I was reading through some documentation.

    I read that DOM objects should be allocated
on stack (basically via local variables of funcions) -- 
I understand why the policy is there.  Removing
and adding nodes of DOM tree can cause havoc 
with C++ pointers.

    My question is: is there a way (even a hacker's way)
around this restriction?  Is there a way to allocate 
DOM document on the heap instead of
on the stack without causing system crashes?  
.
    My problem is that (1) the document must
outlast the routine that created it -- but the automatic
variable mechanism will surely cause my document object to 
vanish when local variables go out of scope.
(2) before a second routine takes over, I need
to place the referene to the document somewhere
(due to the nature of what I am doing, I cannot
just pass the result of that creation to the second 
routine).

    Similarly, if I want to get a child node, I should be able
to do one of the following:

=============================
------

     DOM_Node  *nd = &(doc -> getChildNodes());
     delete nd;  // since I am doing things on the heap 
------
    or have a class wrapper around DOM documement
so that delete is only called implicitly:

class wrapper
{
    DOM_Node nd;
};

============================

    It seems to me that the underlying reference
counting mechanism should work to ensure that
no bad things happen, even if I were to the preceding.
(provided that I have a properly matching destructor
for every constructor).

    From what I understand about stack and heap,
I can't see anything wrong with it, provided I carefully
use delete operator

    Am I wrong?


    I would really be grateful for any comments/help.    

Reply via email to