Last active
November 8, 2017 02:50
-
-
Save kaityo256/32bc425b630642f67e649854104f977e to your computer and use it in GitHub Desktop.
Visualize chunk list of malloc
This file contains hidden or 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 <cstdio> | |
| #include <cstdlib> | |
| #include <omp.h> | |
| const int N = 128; | |
| int | |
| main(int argc, char **argv) { | |
| char *buf[N]; | |
| size_t size = 128; | |
| #pragma omp parallel for | |
| for (int i = 0; i < N; i++) { | |
| buf[i] = (char*)malloc(size); | |
| } | |
| for (int i = 0; i < N; i++) { | |
| for (int j = 0; j < size; j++) { | |
| buf[i][j] = 0; | |
| } | |
| } | |
| for (int i = 0; i < N; i++) { | |
| free(buf[i]); | |
| } | |
| printf("digraph test_%d\n {\n", size); | |
| for (int i = 0; i < N; i++) { | |
| size_t *p = (size_t*)(buf[i]); | |
| size_t prev_size = *(p - 2); | |
| if (prev_size != 0)continue; | |
| size_t *ct = p - 2; | |
| size_t fd = *p; | |
| printf("\"%lx\"->\"%lx\"\n", ct, fd); | |
| } | |
| printf("}\n"); | |
| } |
Author
kaityo256
commented
Nov 8, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
