- 论坛徽章:
- 89
|
本帖最后由 fender0107401 于 2010-10-08 21:14 编辑
- > cat mail.c
- #include <stdio.h>
- #include <stdlib.h>
- #include <malloc_np.h>
- int
- main(void)
- {
- int i = 0,
- j = 4;
- size_t size;
- int *p = NULL;
- int *np = NULL;
- p = malloc(j * sizeof(int));
- size = malloc_usable_size(p);
- printf("%i\n", size);
- np = malloc(j * j * sizeof(int));
- size = malloc_usable_size(np);
- printf("%i\n", size);
- free(np);
- np = p;
- size = malloc_usable_size(np);
- printf("%i\n", size);
- size = malloc_usable_size(p);
- printf("%i\n", size);
- free(p);
- return 0;
- }
- > cc -g mail.c
- > ./a.out
- 16
- 64
- 16
- 16
- >
复制代码 |
|