cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvain Wallez <sylvain.wal...@anyware-tech.com>
Subject Re: [Heads Up] Utility for efficiency
Date Fri, 18 Jan 2002 14:16:28 GMT
Piroumian, Konstantin wrote:

>>Berin Loritsch wrote:
> 
>  <snip/>
> 
>>Buffers are really great for FIFO (first in, first out).
>>
>>For LIFO (last in, first out), the JDK offers java.util.Stack, but its 
>>use should avoided since it is synchronized. There's an unsynchronized 
>>replacement in org.apache.avalon.excalibur.collections.ArrayStack.
> 
> Why not use java.util.LinkedList instead of java.util.Stack?
> 

A LinkedList references the objects it contains using linked (as its 
name implies) nodes that reference values. So a node is created each 
time you add an object, and a node is thrown to garbage each time you 
remove an object.

This implementation is efficient when you have to insert/remove objects 
in the middle of the list : it just has to change some next/previous 
references, while an ArrayList must compact the underlying array.

The particularity of a FIFO is that insert/remove operations always 
occur at the end of the list. An array-based implementation just has to 
change the end-of-list index and the value for this index, while a 
LinkedList must allocate or garbage a new node.

This is why array-based list are more efficient for stacks than linked list.

Sylvain

-- 
Sylvain Wallez
Anyware Technologies - http://www.anyware-tech.com


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message