Is there a way in C to find out the size of dynamically allocated memory?
For example, after
char* p = malloc (100);
Is there
This code will probably work on most Windows installations:
template int get_allocated_bytes(T* ptr) { return *((int*)ptr-4); } template int get_allocated_elements(T* ptr) { return get_allocated_bytes(ptr)/sizeof(T); }