nemo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-nemo] hy00nc commented on a change in pull request #222: [NEMO-350] Implement Off-heap SerializedMemoryStore & [NEMO-384] Implement DirectByteBufferInputStream for Off-heap SerializedMemoryStore
Date Fri, 21 Jun 2019 03:58:19 GMT
hy00nc commented on a change in pull request #222: [NEMO-350] Implement Off-heap SerializedMemoryStore
& [NEMO-384] Implement DirectByteBufferInputStream for Off-heap SerializedMemoryStore
URL: https://github.com/apache/incubator-nemo/pull/222#discussion_r296088315
 
 

 ##########
 File path: common/src/main/java/org/apache/nemo/common/DirectByteBufferOutputStream.java
 ##########
 @@ -140,38 +140,45 @@ public void write(final byte[] b, final int off, final int len) {
     final int arraySize = pageSize * (dataList.size() - 1) + lastBuf.position();
     final byte[] byteArray = new byte[arraySize];
     int start = 0;
-    int byteToWrite;
 
-    for (final ByteBuffer temp : dataList) {
+    for (final ByteBuffer buffer : dataList) {
       // ByteBuffer has to be shifted to read mode by calling ByteBuffer.flip(),
       // which sets limit to the current position and sets the position to 0.
       // Note that capacity remains unchanged.
-      temp.flip();
-      byteToWrite = temp.remaining();
-      temp.get(byteArray, start, byteToWrite);
+      final ByteBuffer dupBuffer = buffer.duplicate();
 
 Review comment:
   It does not literally copy the contents but **share** the same content of the `ByteBuffer`,
while keeping the limit and position independent from the original one. `ByteBuffer` has a
position and limit that it uses to write and read the data. The important thing is that they
are automatically incremented and decremented by read/write(get/put). Every time we re-read
the data or write additional data after reading, etc., it is too complicated to set the position
and limit to the original one again. Sharing the same position and limit will cause these
errors, so it is best to keep independent values of position and limit. This is the most tricky
part of using `ByteBuffer`. Here we assumed that this function is intended for reading the
data from the start. I will comment on that. 👍 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message