notmem() General Function (libc) notmem() Check if memory is allocated int notmem(ptr); char *ptr; notmem checks if a memory block has been allocated by calloc, malloc, or realloc. ptr points to the block to be checked. notmem searches the arena for ptr. It returns one if ptr is not a memory block obtained from malloc, calloc, or realloc, and zero if it is. ***** Example ***** The following example prints a string, and frees it if it was malloc'd. #include <sys/malloc.h> pfree(s) char *s; { printf("%s\n", s); if(!notmem(s)) free(s); } main() { char *mallocked_string; char notmallocked_string[50]; if ((mallocked_string = malloc(50)) == NULL) exit(1); strcpy(mallocked_string, "This is a malloc'd string"); strcpy(notmallocked_string, "This is not a malloc'd string"); pfree(mallocked_string); pfree(notmallocked_string); } COHERENT Lexicon Page 1
notmem() General Function (libc) notmem() ***** See Also ***** arena, calloc(), free(), general functions, malloc(), realloc(), setbuf() COHERENT Lexicon Page 2