Tuesday 8 November 2011

How can you determine the size of an allocated portion of memory? in C programming

How can you determine the size of an allocated portion of memory?

You can’t, really. free() can (see FAQ VII.26), but there’s no way for your program to know the trick free()
uses. Even if you disassemble the library and discover the trick, there’s no guarantee the trick won’t change
with the next release of the compiler. Trying to second guess the compiler this way isn’t just tricky, it’s crazy.

Cross Reference:

VII.26: How does free() know how much memory to release?

No comments:

Post a Comment