Created
September 23, 2016 06:59
-
-
Save gsingh93/40e23880c717b5ffc1c63ea713a22cd9 to your computer and use it in GitHub Desktop.
Print the requested, usable, and real sizes of a heap chunk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <malloc.h> | |
int main() { | |
printf("size of size_t: %zu\n", sizeof(size_t)); | |
int i; | |
for (i = 0; i < 10; i++) { | |
size_t size = i * 8; | |
void *m = malloc(size); | |
printf("requested chunk of size %zu\n", size); | |
printf("malloc_usable_size: %zu\n", malloc_usable_size(m)); | |
printf("real_size: %zu\n", *((size_t*) (m - sizeof(size_t))) - 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment