Hello,
Is it possible to retrieve the size of allocated memory from a pointer (more specifically, a pointer returned my malloc/realloc). This question may have already been asked countless times. However, please consider the following:
I realise that common reactions to such questions include "maintain the size with an int/long/struct" or "use a sentinel", but these approaches would be inappropriate for overloading the assignment constructor (if this was to be used in a class), or efficiency (as decoding escape characters can result in unnecessary overhead) respectively.
If there is a platform-dependent method that requires assembly, please tell me.
Thank you.
Is it possible to retrieve the size of allocated memory from a pointer (more specifically, a pointer returned my malloc/realloc). This question may have already been asked countless times. However, please consider the following:
- The program's heap stores the size of an element
- When you use realloc to allocate more memory, a new address may sometimes be issued in order to accommodate the space demand. In these cases, the existing data is copied to the new location, which seems to indicate that realloc can determine the allocated size
I realise that common reactions to such questions include "maintain the size with an int/long/struct" or "use a sentinel", but these approaches would be inappropriate for overloading the assignment constructor (if this was to be used in a class), or efficiency (as decoding escape characters can result in unnecessary overhead) respectively.
If there is a platform-dependent method that requires assembly, please tell me.
Thank you.
Comment