I have an application that will be reading sequenced packets from a udp connection. These messages need to be stored in some form of buffer with their sequence numbers for lookup.
This ‘buffer’ is serviced by another thread that removes the message and handles it. If a sequence number is missed, I have stop the service thread and then re-request the message on another TCP connection. Once it arrives, I want to plonk it back into the buffer, and the service thread can continue.
So I need : insertions by key, removals by lowest key. The key will be a numerical incrementing number such as 1,2,3,4 so it makes it a bit easier to keep track of the highest number, as the key can thus be incremented/decremented, avoiding the need to sort the datastructure.
My one plan is to use a Dictionary as the buffer, which makes for a simple solution
My other solution uses a set up two queues
Suggestion by zmbg to use SortedList - I am concerned about performance, as hashing would provide faster lookup and insert not?
My questions are:
- Basically I’m looking for pitfalls in terms of memory or performance using a dictionary for this solution. The machine that will run it doesn’t have too much memory, but throughput performance has a slightly higher priority.
- If this application is running all day, would there be any memory related issues when using the dictionary?
- Does anyone have any thoughts on this or alternative implementation of this procedure. I have to decide on a design, but I cannot test different solutions for performance as I don’t quite have enough time, so I thought I’d try a theoretical gathering of ideas and merit of implementation ideas before I start.
I finally decided to implement my own Queue with a Dictionary backing it.
Dictionary provides the insertion and removal performance I am looking for, and pondering too much over small performance issues prematurely is not going to get me nowhere.
Keeping track of the lowest number only is fine, I will not go into too much detail further.