Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most efficient collection for this kind of LILO?

I am programming a list of recent network messages communicated to/from a client. Basically I just want a list that stores up to X number of my message objects. Once the list reaches the desired size, the oldest (first) item in the list should be removed. The collection needs to maintain its order, and all I will need to do is

  1. iterate through it,
  2. add an item to the end, and
  3. remove an item from the beginning, if #2 makes it too long.

What is the most efficient structure/array/collection/method for doing this? Thanks!

like image 634
DivideByHero Avatar asked Dec 12 '25 20:12

DivideByHero


2 Answers

You want to use a Queue.

like image 52
Rich Adams Avatar answered Dec 15 '25 09:12

Rich Adams


I don't think LILO is the real term...but you're looking for a FIFO Queue


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!