StructNew type options

Skip to first unread message

Andrew Penhorwood

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

Jan 28, 2010, 1:59:36 PM1/28/10
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

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.


Barney Boisvert

Michael Offner-Streit

Jan 28, 2010, 2:14:24 PM1/28/10
Basic type, same as if no type is defined.

The order of the keys in the struct is guaranteed.
see also:

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.


p.s. one of the next releases will also support "soft"

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
Railo Technologies GmbH

Mailing List (english):
Mailing List (german):
Linked in:
Issue Tracker:

Reply all
Reply to author
0 new messages