delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/28/01:48:02

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: free()
Date: Sat, 27 Jun 1998 21:45:20 -0700
Organization: Alcyone Systems
Lines: 30
Message-ID: <3595CA60.796C77B4@alcyone.com>
References: <19980623 DOT 131350 DOT 7759 DOT 0 DOT zixyer AT juno DOT com>
NNTP-Posting-Host: kamali.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Zixyer S Qwerty wrote:

> How does free() know how much memory to return to the heap?

Because you allocated it through malloc.

> Does it have
> to be the originally malloc()ed pointer or can it be a different
> pointer
> to the memory that was allocated?

As long as the pointer is to the same address, it's the same pointer.

> I'm writing a linked list and
> keeping
> pointers to each element around kinda defeats the purpose...  thanks
> in
> advance for any help

You certainly need to keep them around while you're still using them. 
Once you don't need to use memory anymore you should free it as soon as
you're done with it.

-- 
         Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
                       Alcyone Systems / http://www.alcyone.com/max/
  San Jose, California, United States / icbm:+37.20.07/-121.53.38
                                     \
                   Regret it? nope. / Said it? yep.
                                   / Ice Cube

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019