On Wed, Jun 15, 2011 at 8:02 AM, Niklas Gustavsson <[email protected]>wrote:
> On Wed, Jun 15, 2011 at 12:41 AM, Allen Firstenberg > <[email protected]> wrote: > > What seems simplest and most efficient to me would be to maintain two > > ordered lists of Integers, "freePorts" and "usedPorts" > In my rough test I changed this from an ordered list to just a list. There is no reason to keep the ordering after it is created. > If desired, I can do an implementation of this. > > Please do. Though, keeping a list of free ports might not be optimal > if the list is long (i.e. a big span of allowed ports). It depends what you mean by "optimal". In some rough tests I did, time to create a PassivePorts object is roughly the same between the two schemes, although time to allocate all 65535 possible ports is 2-3 times slower under the old scheme. Memory is the opposite - my proposed scheme uses 3-4 times the amount of memory the old scheme uses, mostly because of the need to allocate the Integer objects. An implementation that used ints instead of Integers could probably get the memory size to be roughly the same. I know that for my typical uses, this is not a significant amount of memory, and that this would be a reasonable tradeoff for me given the other features this scheme would bring. But I would certainly entertain the notion to make this a more modular component - providing the two implementations (picking one as a default) for the admin to choose between. Thoughts? Allen
