Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of creating <code>temp</code> variable on the stack, I'd create it dynamically (on the heap), but not using raw <code>malloc</code> and <code>free</code> as showed in a previous answer, but using modern C++ and <strong><code>std::vector</code></strong>:</p> <pre><code>#include &lt;vector&gt; std::vector&lt;char&gt; temp(1024*1024); </code></pre> <p>This is exception safe, and you don't have to pay attention to release the allocated memory: <code>std::vector</code>'s destructor will do that <em>automatically</em> (also in case of exceptions thrown).</p> <p>Instead of <code>sizeof(temp)</code>, in your code you can use <code>temp.size()</code> (which will return the count of elements in the vector, and since this is a vector of <code>char</code>s, it will return just the total vector size in <code>char</code>s i.e. in bytes).</p> <p>You can still use <code>operator[]</code> for <code>std::vector</code>, as you do for raw C arrays.</p> <p>Note also that if you are building a <strong>DLL</strong> and the above function is exposed at the DLL interface, since this function has a <strong>C++ interface with a STL class (<code>std::string</code>) at the boundary</strong>, you must pay attention that both your DLL and your clients are built with <em>dynamic linking</em> to the <em>same CRT</em>, and with the <em>same compiler</em> and the <em>same compiler settings</em> (e.g. you can't mix a DLL built with VS2008/VC9 with a .EXE built with VS2010/VC10, or a release-build DLL with a debug-build EXE built with the same compiler).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload