views:

403

answers:

1

I am implementing a sliding window for a trivial protocol. I was implementing the window using a static circular queue (array), as i though it is efficient.
But one of my friends said, he has seen the implementation of sliding window in tcp, it uses a linked list. I dont think he has seen, as he doesnot know where is network code located in the distro.
Anyways, which is a better way to implement the Sliding Window for flow control.
1. a cicular queues
2. a linked list
3. or something else.

any recommendations or code implementation?

A: 

Better is a bit subjective / depends on your goals / how the data structure is used - a linked list may be better to avoid copy over head into the array but this is at the expense of complicating the tracking of the buffers of the list items. Searching a linked list is harder/slower but if you insert more than retrieve, it's a reasonable trade off.

Tony Lee
its not only the linklist traversal which is a matter, malloc is, everytime a malloc is done, a context switch happens... it will be too expensive in terms of efficiency
Vivek Sharma