On Dec 17, 2012, at 2:44 AM, Markos Zaharioudakis <markos...@yahoo.com> wrote:

> size:size(<a><b>foo</b></a>) returns 101. This is wrong because just 
> sizeof(ElementNode) is 52 and the tree <a><b>foo</b></a> consists of 2 
> element nodes, one text node and one (hidden) attribute node. 
> The reason for this wrong result is in this struct:
> template<typename T>
> struct size_traits<T*,false> {
>  static size_t alloc_sizeof( T *p ) {
>    return p ? mem_sizeof( *p ) : 0;
>  }
> };
> Basically, an InternalNode has a vector of XmlNode*. So, the above struct is 
> instantiated with T being XmlNode. Then, mem_sizeof(XmlNode) is called 
> returning just 20 (== sizeof(XmlNode)).

I've looked at this a bit more and I still don't understand why it's wrong.  
Ignoring everything else, the alloc_size() specialization for pointers seems 

For a vector<XmlNode*>, it should iterate through the vector's elements.  For 
each element, it should call the above alloc_sizeof() for XmlNode*.  That in 
turn should call mem_sizeof(XmlNode) which is sizeof(XmlNode) + 
alloc_sizeof(XmlNode).  alloc_sizeof(XmlNode) turns into 

XmlNode is derived from store::Item that has a virtual alloc_size().  The 
specialization of size_traits for classes that have an alloc_size() member 
function is called.  Therefore, I don't see where the mistake is.

- Paul

Your team Zorba Coders is subscribed to branch lp:zorba.

Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to