home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 1963 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: news.ind.mh.se!ing9435
  2. From: ing9435@ind.mh.se (Jimmy Westerlund)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: More linked list nonsense
  5. Date: 25 Jan 1996 11:26:30 GMT
  6. Organization: Mid Sweden University, Dept. of Industrial technology
  7. Message-ID: <4e7pd6$nq2@skarjeke.ind.mh.se>
  8. References: <4e5nih$iib@news.sdd.hp.com>
  9. NNTP-Posting-Host: martin.ind.mh.se
  10. X-Newsreader: slrn (0.8.4)
  11.  
  12. In article <4e5nih$iib@news.sdd.hp.com>, Jeff Grimmett wrote:
  13. >
  14. >Howdy,
  15. >
  16. >It just occurred to me last night, as I pored over steaming code, that 
  17. >the function Remove() (used to remove nodes from linked lists) might 
  18. >POSSIBLY not be freeing the memory allocated to the node it is removing. 
  19.  
  20.  Remove() does NOT(!!) free anykind of allocated memory...
  21.  Just because you Remove() a node from a list doesn't mean that you wan't
  22.  to deallocate it (maybe you want to insert it into another list?)...
  23.  
  24.  What Remove() does is to change the pointers in the nodes before and after 
  25.  so that this node is no longer a part of the list.
  26.  
  27.  Before Remove():
  28.          Node #1    Node #2    Node #3
  29.       -> ln_Succ -> ln_Succ -> ln_Succ ->
  30.  
  31.       <- ln_Pred <- ln_Pred <- ln_pred <-
  32.  
  33.  
  34.  Remove(node #2);
  35.          Node #1    Node #2    Node #3
  36.                   +---------+
  37.       -> ln_Succ -+ ln_Succ +> ln_Succ ->
  38.  
  39.       <- ln_Pred <+ ln_Pred +- ln_pred <-
  40.                   +---------+
  41.  
  42.  (Hope you see what I mean :)
  43.  
  44. >
  45. >Does anyone have some insight on this?  It's difficult to deallocate a 
  46. >node once it's not part of the list, but it's pretty STUPID to free it 
  47. >BEFORE. :-)
  48.  
  49.  Nope, it shouldn't be any problem for you to deallocate it (I do suppose
  50.  you are the one that allocated the node in the first place ???) because
  51.  you still got the pointer to it...
  52.  
  53. >
  54. >It's also hard to imagine that C= gave us this function without some way 
  55. >to clean up behind it, but I'm SUCH a Doubting Thomas at times... :-)
  56. >
  57.  
  58.  Remove(node);
  59.  FreeVec(node); 
  60.  
  61.  
  62.   /Jimmy Westerlund -- ing9435@ind.mh.se, jimmy@eagle.ovik.se
  63.  
  64.  
  65.