From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Peter A. Friend" To: "Ben A. Abderrazek" Cc: help-gcc@gnu.org Subject: Re: LRU algorithm Date: Thu, 02 Dec 1999 09:13:00 -0000 Message-id: References: <3845EB92.3DE5D53E@sowa.is.uec.ac.jp> X-SW-Source: 1999-12/msg00027.html Well, that depends on how fancy you want to get. I use LRU for a cache of log file descriptors in Apache. It is simply a doubly linked list of structures. The basic operation is: o If an oldest item is needed (to be re-used, or whatever), take it from the tail of the list. o Move the old item you just grabbed to the head of the list. o If you are re-using at item from somewhere in the middle of the list, also move it to the head of the list before using it. The idea is the the items that get "hit" most are going to be at the head of the list, and the oldest at the tail. This approach may or may not work for you, as you may not want to do all of the pointer juggling. As for implementing this in gcc, all that you really have to do is manipulate the doubly linked list. This structure is discussed at length in numerous texts, I can suggest some if you like. BTW, this isn't really a gcc specific question, as this can be done in any language. Any further discussion should be done privately or on one of the comp.lang newsgroups. HTH, Peter --- Software Engineer EarthLink Network On Thu, 2 Dec 1999, Ben A. Abderrazek wrote: > > Hi all, > > Is any one has a hint about how to write an LRU algorithm in gcc ? > > I have some variables and I want to find the least recently used. > > > Thank you for any help, > > Ben, From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Peter A. Friend" To: "Ben A. Abderrazek" Cc: help-gcc@gnu.org Subject: Re: LRU algorithm Date: Fri, 31 Dec 1999 22:24:00 -0000 Message-ID: References: <3845EB92.3DE5D53E@sowa.is.uec.ac.jp> X-SW-Source: 1999-12n/msg00027.html Message-ID: <19991231222400.rT-YEfHR2Ia_MJtebVth2JyLb3oy2v9uwf2ILRLaU3I@z> Well, that depends on how fancy you want to get. I use LRU for a cache of log file descriptors in Apache. It is simply a doubly linked list of structures. The basic operation is: o If an oldest item is needed (to be re-used, or whatever), take it from the tail of the list. o Move the old item you just grabbed to the head of the list. o If you are re-using at item from somewhere in the middle of the list, also move it to the head of the list before using it. The idea is the the items that get "hit" most are going to be at the head of the list, and the oldest at the tail. This approach may or may not work for you, as you may not want to do all of the pointer juggling. As for implementing this in gcc, all that you really have to do is manipulate the doubly linked list. This structure is discussed at length in numerous texts, I can suggest some if you like. BTW, this isn't really a gcc specific question, as this can be done in any language. Any further discussion should be done privately or on one of the comp.lang newsgroups. HTH, Peter --- Software Engineer EarthLink Network On Thu, 2 Dec 1999, Ben A. Abderrazek wrote: > > Hi all, > > Is any one has a hint about how to write an LRU algorithm in gcc ? > > I have some variables and I want to find the least recently used. > > > Thank you for any help, > > Ben,