← Back to team overview

zorba-coders team mailing list archive

Re: [Merge] lp:~zorba-coders/zorba/feature-mem_size into lp:zorba

 

On Dec 17, 2012, at 2:44 AM, Markos Zaharioudakis <markos_za@xxxxxxxxx> 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).  alloc_sizeof(XmlNode) turns into size_traits<XmlNode>::alloc_sizeof(t).

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


-- 
https://code.launchpad.net/~zorba-coders/zorba/feature-mem_size/+merge/114764
Your team Zorba Coders is subscribed to branch lp:zorba.


Follow ups

References