<div dir="ltr">Alex,<div><br></div><div>The reason I was trying to find an alternative because this 'wireEncode()' code path is one of the major memory consumer in ndnSIM. Although there are optimizations provided by caching the block size after first encode(), it appears that memory is not freed after first encode. </div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div>==9587== 100,926,144 bytes in 73,852 blocks are still reachable in loss record 1,226 of 1,228 </div></div><div><div>==9587==    at 0x4C2B0E0: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)</div></div><div><div>==9587==    by 0x69A08DF: allocate (new_allocator.h:104)</div></div><div><div>==9587==    by 0x69A08DF: _M_allocate (stl_vector.h:168)</div></div><div><div>==9587==    by 0x69A08DF: void std::vector<ndn::Block, std::allocator<ndn::Block> >::_M_emplace_back_aux<ndn::Block>(ndn::Block&&) (vector.tcc:404)</div></div><div><div>==9587==    by 0x699C79C: emplace_back<ndn::Block> (vector.tcc:101)</div></div><div><div>==9587==    by 0x699C79C: push_back (stl_vector.h:920)</div></div><div><div>==9587==    by 0x699C79C: ndn::Block::parse() const (block.cpp:347)</div></div><div><div>==9587==    by 0x6A1F5A8: ndn::Name::wireEncode() const (name.cpp:102)</div></div><div><div>==9587==    by 0x6B4619F: nfd::DeadNonceList::makeEntry(ndn::Name const&, unsigned int) (dead-nonce-list.cpp:108)</div></div><div><div>==9587==    by 0x6B4621D: nfd::DeadNonceList::has(ndn::Name const&, unsigned int) const (dead-nonce-list.cpp:92)</div></div><div><div>==9587==    by 0x6B25A42: nfd::Forwarder::onIncomingInterest(nfd::Face&, ndn::Interest const&) (forwarder.cpp:86)</div></div><div><div>==9587==    by 0x69B066A: operator() (functional:2471)</div></div><div><div>==9587==    by 0x69B066A: operator() (signal-signal.hpp:241)</div></div><div><div>==9587==    by 0x69B066A: operator() (signal-signal.hpp:255)</div></div><div><div>==9587==    by 0x69B066A: emit_onReceiveInterest<ndn::Interest, ndn::util::signal::DummyExtraArg> (face.hpp:194)</div></div><div><div>==9587==    by 0x69B066A: ndn::Face::Impl::asyncExpressInterest(std::shared_ptr<ndn::Interest const> const&, std::function<void (ndn::Interest const&, ndn::Data&)> const&, std::function<void (ndn::Interest const&)> const&) (face-impl.hpp:170)</div></div><div><div>==9587==    by 0x69AD13B: operator() (face.cpp:69)</div></div><div><div>==9587==    by 0x69AD13B: std::_Function_handler<void (), ndn::Face::expressInterest(ndn::Interest const&, std::function<void (ndn::Interest const&, ndn::Data&)> const&, std::function<void (ndn::Interest const&)> const&)::{lambda()#1}>::_M_invoke(std::_Any_data const&) (functional:2071)</div></div><div><div>==9587==    by 0xB84EC6C: ns3::DefaultSimulatorImpl::ProcessOneEvent() (default-simulator-impl.cc:149)</div></div></blockquote><div><br></div><div>/anil.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 5, 2016 at 2:29 PM, Alex Afanasyev <span dir="ltr"><<a href="mailto:aa@cs.ucla.edu" target="_blank">aa@cs.ucla.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On May 4, 2016, at 4:05 PM, Anil Jangam <<a href="mailto:anilj.mailing@gmail.com">anilj.mailing@gmail.com</a>> wrote:<br>
><br>
</span><div><div class="h5">> Hi.<br>
><br>
> Calculating the size of Interest/Data packet wire, L3 tracer is done using the wireEncode() API.<br>
><br>
> <a href="https://github.com/named-data-ndnSIM/ndnSIM/blob/master/utils/tracers/ndn-l3-rate-tracer.cpp#L294" rel="noreferrer" target="_blank">https://github.com/named-data-ndnSIM/ndnSIM/blob/master/utils/tracers/ndn-l3-rate-tracer.cpp#L294</a><br>
><br>
> if (interest.hasWire()) {<br>
>     std::get<1>(m_stats[face.shared_from_this()]).m_outInterests +=<br>
>     interest.wireEncode().size();<br>
> }<br>
><br>
> In the implementation of wireEncode() also, the same check is being done.<br>
><br>
> <a href="https://github.com/named-data-ndnSIM/ndn-cxx/blob/36ec104e23ba5395a8b4df411b776cdbef9c5cd4/src/interest.cpp#L279" rel="noreferrer" target="_blank">https://github.com/named-data-ndnSIM/ndn-cxx/blob/36ec104e23ba5395a8b4df411b776cdbef9c5cd4/src/interest.cpp#L279</a><br>
> const Block&<br>
> Interest::wireEncode() const<br>
> {<br>
>     if (m_wire.hasWire())<br>
>     return m_wire;<br>
>     ...<br>
> }<br>
><br>
> Perhaps this is a redundant check inside L3 tracer. But, is this the only way to know the size of data being transferred over or received from the face?<br>
><br>
> /anil.<br>
<br>
<br>
</div></div>To know the size of the packet, one need to create the wire encoding of the packet.  "wireEncode()" method doesn't encode all the time, but rather encodes once and caches the encoding for future reuse.  Exception here are cases when some fields of the Interest are modified, in which case the cached version of the wire encoding is removed.<br>
<br>
The guard in interest.cpp, is to simply return the cached version of wire if it exists (not to encode again).<br>
<br>
The guard in L3Tracer serves an optimization different role for ndnSIM-native apps (ndn::Consumer*).  When interest/data are exchanged between these apps and L3 stack, the wire format is not created at all.  It gets created only when packet is moved through the actual wire ("Channel").  This optimization does not apply for apps that are based on ndn-cxx Face emulation.<br>
<br>
--<br>
Alex<br>
</blockquote></div><br></div>