.TH notmem() "" "" "General Function (libc)"
.PC "Check whether memory is allocated"
\fBint notmem(\fIptr\^\fB);\fR
\fBchar *\fIptr\^\fB;\fR
.PP
.B notmem()
checks if a memory block has been allocated by
.BR calloc() ,
.BR malloc() ,
or
.BR realloc() .
.I ptr
points to the block to be checked.
.PP
.B notmem()
searches the arena for
.IR ptr .
It returns one if
.I ptr
is not a memory block obtained from
.BR malloc() ,
.BR calloc() ,
or
.BR realloc() ,
and zero if it is.
.\".SH Example
.\"The following example prints a string, and frees it if it was
.\".BR malloc 'd.
.\".DM
.\"#include <stdlib.h>
.\"#include <unistd.h>
.\".DE
.\".DM
.\"pfree(s)
.\"char *s;
.\"{
.\"	printf("%s\en", s);
.\"	assert(notmem(s));
.\"	free(s);
.\"}
.\".DE
.\".DM
.\"main()
.\"{
.\"	char *mallocked_string;
.\"	char notmallocked_string[50];
.\".DE
.\".DM
.\"	if ((mallocked_string = malloc(50)) == NULL)
.\"		exit(EXIT_FAILURE);
.\".DE
.\".DM
.\"	strcpy(mallocked_string, "This is a malloc'd string");
.\"	strcpy(notmallocked_string, "This is not a malloc'd string");
.\".DE
.\".DM
.\"	pfree(mallocked_string);
.\"	pfree(notmallocked_string);
.\"	exit(EXIT_SUCCESS);
.\"}	
.\".DE
.SH "See Also"
.Xr "arena," arena
.Xr "calloc()," calloc
.Xr "free()," free
.Xr "libc," libc
.Xr "malloc()," malloc
.Xr "memok()," memok
.Xr "realloc()," realloc
.Xr "setbuf()" setbuf
.SH Notes
The only valid use for
.B notmem()
is in debugging code, such as in the bodies of calls to the macro
.BR assert() .
We furthermore recommend
that portable code should conditionalize use of
.B notmem()
so that the code may continue to compile on systems that lack such a facility.

