> 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
> correct.
> 
> 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).

Here is the 1st problem: inside mem_sizeof(const XmlNode& t), sizeof(T) (or 
sizeof(t)) should return 52 if t is actually an ElementNode. Of course, this is 
not possible since sizeof(T) is computed statically (i.e., at compile time).

> alloc_sizeof(XmlNode) turns into
> size_traits<XmlNode>::alloc_sizeof(t).
> 

And here is the 2nd problem: alloc_sizeof(XmlNode) turns into 
size_traits<XmlNode, false>::alloc_sizeof(t), which returns 0. Somehow, the 
trick with the has_alloc_size class does not work.

> 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


Try stepping through this example with gdb, and you will see it yourself.
-- 
https://code.launchpad.net/~zorba-coders/zorba/feature-mem_size/+merge/114764
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