mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
updated readme
This commit is contained in:
@@ -424,7 +424,10 @@ BondVOInterface bond = map.get(key);
|
||||
bond.getCoupon()
|
||||
|
||||
```
|
||||
lets say that it is only the `coupon` field that we are interested in, then its better not to have to deserialize the whole object that implements the `BondVOInterface`. It would be more efficient to just deserialize the field(s) that we require, in this example just the coupon. This is why we created the`OffHeapUpdatableChronicleMapBuilder`, when you use this builder chronicle will not create on heap copies of your whole DataStructure. You can instead use proxy objects that can read and write into the off heap data structures, this reduced serialisation can give you a big performance boost. Below we show you how you can work directly with the off heap entries.
|
||||
lets say that it is only the `coupon` field that we are interested in, then its better not to have to
|
||||
deserialize the whole object that implements the `BondVOInterface`. It would be more efficient to just
|
||||
deserialize the field(s) that we require, in this example just the coupon. This is why we created
|
||||
the`OffHeapUpdatableChronicleMapBuilder`, when you use this builder chronicle will not create on heap copies of your whole data structure. You can instead use proxy objects that can read and write into the off heap data structures, this reduced serialisation can give you a big performance boost. Below we show you how you can work directly with the off heap entries.
|
||||
|
||||
``` java
|
||||
ChronicleMap<String, BondVOInterface> chm = OffHeapUpdatableChronicleMapBuilder
|
||||
@@ -443,13 +446,14 @@ value class, in our case `BondVOInterface.class` is an `interface` rather than a
|
||||
class that class has to extend `Byteable`), now
|
||||
like before, we can
|
||||
use the `getUsing(key,using)` method, but this time we have to create the ‘using’ instance slightly
|
||||
differently
|
||||
differently, we have to call the `newDirectReference(..)` method.
|
||||
|
||||
``` java
|
||||
BondVOInterface using = DataValueClasses.newDirectReference(BondVOInterface.class);
|
||||
```
|
||||
|
||||
now we can call
|
||||
the call to get using is the same
|
||||
|
||||
|
||||
``` java
|
||||
BondVOInterface bond = map.getUsing(key,value);
|
||||
@@ -457,8 +461,8 @@ BondVOInterface bond = map.getUsing(key,value);
|
||||
|
||||
this won’t create any on heap objects, and it won’t deserialize the ‘bond’ entry from off heap to on
|
||||
heap, all it does is sets the bond as a proxy to the off heap memory, this proxy object was created by
|
||||
`DataValueClasses.newDirectReference(BondVOInterface.class)` it allows us access the fileds for our entry
|
||||
directly from the off heap storage,
|
||||
`DataValueClasses.newDirectReference(BondVOInterface.class)`, it allows us access to the fields of our
|
||||
entry, directly into the off heap storage.
|
||||
|
||||
so when you call :
|
||||
|
||||
@@ -470,7 +474,7 @@ its only the coupon that gets deserialized.
|
||||
|
||||
|
||||
Just like any other concurrent map, chronicle map uses segment locking, if you wish to obtain a read lock
|
||||
when calling when calling getUsing(key,using) you can do this :
|
||||
when calling getUsing(key,using) you can do this :
|
||||
|
||||
``` java
|
||||
try (ReadContext<?, BondVOInterface> context = map.getUsingLocked(key,using)) {
|
||||
@@ -497,7 +501,7 @@ If you wish not to use a try block you must manually release the segment lock by
|
||||
context.close() // the lock will get released when this is called
|
||||
```
|
||||
|
||||
#### what acquireUsingLocked()
|
||||
#### acquireUsingLocked()
|
||||
|
||||
just like getUsing(), acquireUsing() will also recycle the value you pass it, the following
|
||||
code is a pattern that you will often come across, acquireUsing(key,value) offers this
|
||||
@@ -542,7 +546,7 @@ try (WriteContext<?, BondVOInterface> context = map.acquireUsingLocked("one", bo
|
||||
}
|
||||
```
|
||||
|
||||
if after you have read the 'issueDate' and 'symbol' you wish to remove the entry based on some
|
||||
if after you have read the 'issueDate' and 'symbol' and you wish to remove the entry based on some
|
||||
business logic, it more efficient to use the 'context' to remove the entry, as the contents is
|
||||
already aware when the entry is in memory.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user