Re: [CODE] Memory Allocation Check

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 11/10/00


Karl Buchner wrote:
>
> May be a stupid question, but is there any way to see if a block of memory has been allocated?  Specifically, I have a pointer to a character, and want to check if the character has been free()'d.

First off, please set your email client to wrap lines at 75 characters
when posting to the list.

To do this you must make sure and follow a ceartain convention when
freeing memory.  More specifically what you want to do is make sure and
follow a `free(x);' with `x=NULL;'.

Then you can easily check to see if it points to valid memory simply by
doing this...

if (x) {
  /* memory is valid */
} else {
  /* memory is not valid */
}

Regards, Peter


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/11/01 PDT