Results 1 to 5 of 5

Thread: Removing old data from a stringlist

  1. #1

    Removing old data from a stringlist

    Hello,

    I'm using the Delphi StringList as a buffer to hold data. This data is sent out of a socket when the link is available else the data is stored in the list. As I don't want the list to grow out of control I'm allowing the user to define a maximum size for the list and a life for each entry. The life of an entry is in the range of 1 minute to 24 hours in minute increments, this is a global setting so all items have this limit. I had planned to look at the oldest item on the list every minute and remove it when it exceeds the defined time. My problem is how to best to define when an item is too old and should be removed. My initial thought was that when I add an item to the list I use the current time + the timeout. When I check the first item (which will be the oldest), I check to see if that time is met and remove it. I then check the next item and if that's ok I go back to checking every minute etc. This method isn't good as it will go wrong if the user changes the pc time or the clock changes for daylight saving. What about if I have an internal counter that starts at 0 and is incremented every minute. I could use the above method but use the counter rather than the pc time. Any other ideas ?

  2. #2

    Removing old data from a stringlist

    just deleting the entry does not free the data?

    I think Modern Pascal (FP,Delphi) handles string data automatically
    From brazil (:

    Pascal pownz!

  3. #3

    Removing old data from a stringlist

    Daylight saving or user changes time are very rare occasions

    I would just do this:

    Code:
    while (first_item_in_list is too old) OR (list.count >= maximum user defined size)
      delete first item
    ZGameEditor - Develop 64kb games for Windows.
    Thrust for Vectrex - ROM-file and 6809 source code.

  4. #4

    Removing old data from a stringlist

    I would use a TQueue for that, because the situation you describe asks for a FIFO datastructure (first-in-first-out). A list could work here, but a Queue is more appropriate IMHO.

    Writing your own timer is a good sollution, but i don't see many reasons why users should change the system time (At least i don't change it, except for the summer-time to winter-time switch). You would also ask yourself whether it is a bad bug or not. In some cases it would totally disorganize the system, but in most cases it doesn't matter IMHO. If it's a real big chunk of data, i suggest you write it to your HDD, instead of keeping it in RAM. When using the great ammount of space usually available on a harddrive, it might be unnecessary to use lifetime for your data.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  5. #5

    Re: Removing old data from a stringlist

    Quote Originally Posted by ianatwork
    What about if I have an internal counter that starts at 0 and is incremented every minute. I could use the above method but use the counter rather than the pc time.
    That's probably the best solution. Also, you could use another thread that would work as the counter and maybe a yet another one for deleting the data if it's too old. That would make your application multithreaded. But be careful when sharing data between many threads - I suggest you use critical sections - they are the best solution IMHO.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •