Re: some

57 views
Skip to first unread message

Peter Lawrey

unread,
Sep 13, 2016, 2:52:12 AM9/13/16
to java-ch...@googlegroups.com

Hello Felix,
   Instead of using fixed length value you can use variable length values. Ie you can use CharSequence as your value type. This works well when there is variation in the length and you don't need composite data.

Regards, Peter.


On 13 Sep 2016 06:50, "Felix" <felixu...@gmail.com> wrote:


I clearly understand the trade-off for the speed of memory access versus dynamic memory management and why ChronicleMap needs to be fairly rigid on the specification of data types and allocation of memory chunks.

I am faced with the fact that in terms of String entries my program could face various lenths entries from
0 to thousands of characters (I'd like to accommodate even MBs) to be handled in ChronicleMap. The shorter strings would have many entries, while the long ones would have fewer entries.

To avoid unnecessary memory fragmentation and RAM waste, I am thinking of designing some 32 CharSequence based ChronicleMap instances
having a 'long' K (key) each instance value handling blocks of: 2^P (where P is power of 1 - 32) giving me some 32 instances each handling strings for their own range. For example strings of lengths from 8-15 chars go to map[4], 16-31 chars go to map[5], 32-65 chars go to map[6], etc.
I know this is a rigid approach but that is the reason for posting this. Would you please suggest if there is a better way to address the large differences on string lengths dynamically? 

Now if I still go with the described approach - ChronicleMap doc. suggests for Strings using interfaces of the below design.


   
   
public interface StrLenPowerOf4 {
       
CharSequence getValue();
       
void setValue(@NotNull @MaxUtf8Length(16) CharSequence value);
   
}
   
   
   
public interface StrLenPowerOf5 {
       
CharSequence getValue();
       
void setValue(@NotNull @MaxUtf8Length(32) CharSequence value);
   
}
   
   
   
public interface StrLenPowerOf6 {
       
CharSequence getValue();
       
void setValue(@NotNull @MaxUtf8Length(64) CharSequence value);
   
}
   


From what I know, annotations can hardly accept a variable, so am I faced with setting 32 interfaces as in the example, or is there an idea for more flexible interface?

Thank you kindly.

--
You received this message because you are subscribed to the Google Groups "Chronicle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicle+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Felix

unread,
Sep 13, 2016, 3:55:49 AM9/13/16
to Chronicle
Well, of course, I totally "over-engineered" this. And the .averageValueSize for the approximate lengths. Thanks for the wake up kick, Peter.
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicl...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages