<p>Because the whole point of the new code is to get rid of the dynamic allocation if that is possible, using a std::string for the same thing would require an allocator with static storage - and introducing such would in my opinion by far too complex to be worth it.</p>
<p>The current implementation is cleaner than conditionally using a std::string (which indirectly will do dynamic initialization).</p>
<p>/F</p>
<hr style="height:1px;margin-bottom:20px;background-color:#ddd;color:#ddd" />
<p>On 16/03/07 11:05, Denis Charmet wrote:</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p>Hi,</p>
<p>On 2016-03-04 17:04, Filip Roséen wrote:</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p>+void MkvTree_va( demux_t& demuxer, int i_level, const char* fmt, va_list args) +{ + static char const * indent = “|”; + static char const * prefix = “+”; + static int const indent_len = strlen( indent ); + static int const prefix_len = strlen( prefix ); + + char fixed_buffer[256] = {}; + size_t const static_len = sizeof( fixed_buffer ); + char * buffer = fixed_buffer; + size_t total_len = indent_len * i_level + prefix_len + strlen( fmt ); + + if( total_len >= static_len ) { + buffer = new (std::nothrow) char[total_len] (); + + if (buffer == NULL) { + msg_Err (&demuxer, “Unable to allocate memory for format string”); + return; + } + }</p>
</blockquote>
<p>Since you’re cpping everything why not using std::string? :)</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<ul>
<li></li>
<li>char * dst = buffer;</li>
<li></li>
<li>for (int i = 0; i < i_level; ++i, dst += indent_len)</li>
<li><pre><code> memcpy( dst, indent, indent_len );</code></pre></li>
<li></li>
<li>strcat( dst, prefix );</li>
<li>strcat( dst, fmt );</li>
<li></li>
<li>msg_GenericVa( &demuxer, VLC_MSG_DBG, buffer, args );</li>
<li></li>
<li>if (buffer != fixed_buffer)</li>
<li><pre><code> delete [] buffer;</code></pre>
+}</li>
<li>+void MkvTree( demux_t & demuxer, int i_level, const char *psz_format, … ) +{</li>
<li>va_list args; va_start( args, psz_format );</li>
<li>MkvTree_va( demuxer, i_level, psz_format, args );</li>
<li>va_end( args ); +} diff –git a/modules/demux/mkv/util.hpp b/modules/demux/mkv/util.hpp index 8c6cc6a..5867d1d 100644 — a/modules/demux/mkv/util.hpp +++ b/modules/demux/mkv/util.hpp @@ -90,3 +90,7 @@ public: };</li>
</ul>
<p>block_t * packetize_wavpack( mkv_track_t <em>, uint8_t </em>, size_t); + +/* helper functions to print the mkv parse tree <em>/ +void MkvTree_va( demux_t& demuxer, int i_level, const char</em> fmt, va_list args); +void MkvTree( demux_t & demuxer, int i_level, const char *psz_format, … );</p>
</blockquote>
<h3 id="regards">Regards,</h3>
<p>Denis Charmet - TypX Le mauvais esprit est un art de vivre _______________________________________________ vlc-devel mailing list To unsubscribe or modify your subscription options: https://mailman.videolan.org/listinfo/vlc-devel</p>
</blockquote>