Re: Prevayler-Discussion Digest, Vol 34, Issue 1
Angelo Schneider <[email protected]>
| Newsgroups | gmane.comp.java.prevayler |
|---|---|
| Message-ID | <[email protected]> |
Hello all, Hello Karl, > > Message: 5 > Date: Sun, 15 Aug 2010 08:51:27 +0200 > From: Karl Wettin <[email protected]> > Subject: [Prevayler-discussion] Prevayled flyweight strings > To: "Open discussion about the Prevayler project." > <[email protected]> > Message-ID: <[email protected]> > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes > > In my application there is a lot RAM to be saved by flyweighting > Strings -- I have lots and lots of reoccuring address components. I do > however belive that String.intern is not applicable as it will loose > the state when restarting and I would thus have to add my own > flyweight to the Root. > > Is there any specific solution you would recommend? I was simply > thinking a Map<String, String> where key and value is the same > instance. I think the GOF-bible speak of another solution but I can't You hardly can call that flyweighting, but I guess we all understand what you want to achieve. According to GOF flyweeighting means you split up an object in to the flyweight (which saves RAM and might be easy used/aggregated in Arrays and and some further Object that describes/enriches single objects or arrays of those new Flyweights. Example: Use char arrays instead of strings and have some FontDescription point into start and end positions of such arrays to define the font etc. of the covered chars. Ofc the Chars are usually just an attribute in an object and the object might have a pointer back to its "describing" Object. Your Map<String, String> idea might work. > seem to find it in my library. They probably over complicated things. > > But this should be a rather common use case of Prevayler, right? > > One alternative to the Map I can think of is to programmatically > iterate all my flyweighted values on initialization of the system, > calling String.intern. Not sure if I can trust all JVMs to act the I would _not_ do that. If you "intern" strings they usually land in an area of the VM where they never get garbage collected. That means you have to experiment with JVM -X starting options, like -XX:MaxPermSize=64m. (Choosing the wrong size will let your VM terminate with an OutOfMemoryException, even if you still have lots of free RAM). Please refer to: http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html and: http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html If you traverse the side a big higher you find also informations for solaris and linux ... I think on Macs you have no issue regarding Perm-Sizes as the GC works different. > same way though -- ie using the first interned value as the > flyweighted value. Nor am I sure it would save RAM. It would however > make it slower to start up the system. > > Any thoughts most welcome. For now I'm going with the Map. > > > > karl Best Regards, Angelo --------------------------- www.oomentor.de -------------------------- Angelo Schneider OOAD/UML [email protected] Putlitzstr. 24 Patterns/FrameWorks Fon: +49 721 9812465 76137 Karlsruhe C++/JAVA Mob: +49 172 9873893 ------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev _______________________________________________ To unsubscribe go to the end of this page: http://lists.sourceforge.net/lists/listinfo/prevayler-discussion _______________________________________________ "Databases in Memoriam" -- http://www.prevayler.org