home *** CD-ROM | disk | FTP | other *** search
- Path: news.ind.mh.se!ing9435
- From: ing9435@ind.mh.se (Jimmy Westerlund)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: More linked list nonsense
- Date: 25 Jan 1996 11:26:30 GMT
- Organization: Mid Sweden University, Dept. of Industrial technology
- Message-ID: <4e7pd6$nq2@skarjeke.ind.mh.se>
- References: <4e5nih$iib@news.sdd.hp.com>
- NNTP-Posting-Host: martin.ind.mh.se
- X-Newsreader: slrn (0.8.4)
-
- In article <4e5nih$iib@news.sdd.hp.com>, Jeff Grimmett wrote:
- >
- >Howdy,
- >
- >It just occurred to me last night, as I pored over steaming code, that
- >the function Remove() (used to remove nodes from linked lists) might
- >POSSIBLY not be freeing the memory allocated to the node it is removing.
-
- Remove() does NOT(!!) free anykind of allocated memory...
- Just because you Remove() a node from a list doesn't mean that you wan't
- to deallocate it (maybe you want to insert it into another list?)...
-
- What Remove() does is to change the pointers in the nodes before and after
- so that this node is no longer a part of the list.
-
- Before Remove():
- Node #1 Node #2 Node #3
- -> ln_Succ -> ln_Succ -> ln_Succ ->
-
- <- ln_Pred <- ln_Pred <- ln_pred <-
-
-
- Remove(node #2);
- Node #1 Node #2 Node #3
- +---------+
- -> ln_Succ -+ ln_Succ +> ln_Succ ->
-
- <- ln_Pred <+ ln_Pred +- ln_pred <-
- +---------+
-
- (Hope you see what I mean :)
-
- >
- >Does anyone have some insight on this? It's difficult to deallocate a
- >node once it's not part of the list, but it's pretty STUPID to free it
- >BEFORE. :-)
-
- Nope, it shouldn't be any problem for you to deallocate it (I do suppose
- you are the one that allocated the node in the first place ???) because
- you still got the pointer to it...
-
- >
- >It's also hard to imagine that C= gave us this function without some way
- >to clean up behind it, but I'm SUCH a Doubting Thomas at times... :-)
- >
-
- Remove(node);
- FreeVec(node);
-
-
- /Jimmy Westerlund -- ing9435@ind.mh.se, jimmy@eagle.ovik.se
-
-
-