StructNew type options

80 views
Skip to first unread message

Andrew Penhorwood

unread,
Jan 28, 2010, 1:51:15 PM1/28/10
to Railo
In the function documentation there is this line for StructNew()

the type the new struct (normal,weak,linked)

What does each of these "types" do?

Barney Boisvert

unread,
Jan 28, 2010, 1:59:36 PM1/28/10
to ra...@googlegroups.com
I haven't looked at the code, but from the names I'd expect this:

- "normal" is a simple java.util.Map (most likely java.util.HashMap)
- name value pairs with non-stable ordering of keys. This handles
most cases.
- "linked" is a java.util.LinkedHashMap - the same as a HashMap,
except with a predictable ordering of keys. This carries a slight
performance and memory penalty over a normal HashMap, but ensures that
you always iterate over your keys in the order they were added to the
Map. Often useful for UI stuff where order is important (people
typically care about order - for visual scanning - but machines
usually don't).
- "weak" is a java.util.WeakHashMap - the same as a map except that
keys are available to be garbage collected (which means mappings might
disappear on you). This is good for caches and stuff where you can
rebuild a missing key on demand, so you don't have to worry about
purging the cache to keep your memory load; the JVM will do it for you
(if you're careful). In general usage, this isn't an interesting
option.

There would also be the potential to add a fourth type: "sorted",
which would be a java.util.SortedMap (most likely a java.util.TreeMap)
which always iterates over it's keys in sorted order (rather than
insertion order), based on either natural ordering (alphabetic for
strings) or a Comparator.

cheers,
barneyb

--
Barney Boisvert
bboi...@gmail.com
http://www.barneyb.com/

Michael Offner-Streit

unread,
Jan 28, 2010, 2:14:24 PM1/28/10
to ra...@googlegroups.com
structNew("normal")
Basic type, same as if no type is defined.

structNew("linked")
The order of the keys in the struct is guaranteed.
see also:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/LinkedHashMap.html

structNew("weak")
The content of the might be flushed by the garbage collector. Weak
structures can perfectly be used as caches. In case of a memory
emergency the JRE garbage collector removes elements of weak structures
with a higher priority.
see
also:http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ref/WeakReference.html

/micha

p.s. one of the next releases will also support "soft"
see:http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ref/SoftReference.html

Andrew Penhorwood schrieb:


> In the function documentation there is this line for StructNew()
>
> the type the new struct (normal,weak,linked)
>
> What does each of these "types" do?
>
>


--
Michael Offner-Streit
CTO
Railo Technologies GmbH
michael...@railo.ch
www.getrailo.com

Mailing List (english): http://groups.yahoo.com/group/railo_talk/
Mailing List (german): http://de.groups.yahoo.com/group/railo/
Linked in: http://www.linkedin.com/e/gis/71368/0CF7D323BBC1
Issue Tracker: http://jira.jboss.org/jira/browse/RAILO
Blog: http://www.railo-technologies.com/blog


Reply all
Reply to author
Forward
0 new messages