title: How can I get the size of a memory block allocated using malloc()?
body: <blockquote>
  <p><strong>Possible Duplicates:</strong><br />
  <a href="https://stackoverflow.com/questions/232691/how-can-i-get-the-size-of-an-array-from-a-pointer-in-c">How can I get the size of an array from a pointer in C?</a><br />
  <a href="https://stackoverflow.com/questions/197839/is-there-any-way-to-determine-the-size-of-a-c-array-programmatically-and-if-n">Is there any way to determine the size of a C++ array programmatically?  And if not, why?</a></p>
  </blockquote>
  <p>I get a pointer to a chunk of allocated memory out of a C style function.
  Now, it would be really interesting for debugging purposes to know how
  big the allocated memory block that this pointer points is.</p>
  <p>Is there anything more elegant than provoking an exception by blindly running over its boundaries?</p>
  <p>Thanks in advance,
  Andreas</p>
  <h3>EDIT:</h3>
  <p>I use VC++2005 on Windows, and GCC 4.3 on Linux</p>
  <h3>EDIT2:</h3>
  <p>I have <code>_msize</code> under VC++2005
  Unfortunately it results in an exception in debug mode....</p>
  <h3>EDIT3:</h3>
  <p>Well. I have tried the way I described above with the exception, and it works.
  At least while I am debugging and ensuring that immediately after the call
  to the library exits I run over the buffer boundaries. Works like a charm.</p>
  <p>It just isn't elegant and in no way usable in production code.</p>