You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directmemory.apache.org by bp...@apache.org on 2012/03/02 14:00:54 UTC

svn commit: r1296184 - in /incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator: FixedSizeByteBufferAllocatorImpl.java MergingByteBufferAllocatorImpl.java

Author: bperroud
Date: Fri Mar  2 13:00:54 2012
New Revision: 1296184

URL: http://svn.apache.org/viewvc?rev=1296184&view=rev
Log:
Replacing Set by List as size is know and only iteration is performed, adding more comment

Modified:
    incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/FixedSizeByteBufferAllocatorImpl.java
    incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImpl.java

Modified: incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/FixedSizeByteBufferAllocatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/FixedSizeByteBufferAllocatorImpl.java?rev=1296184&r1=1296183&r2=1296184&view=diff
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/FixedSizeByteBufferAllocatorImpl.java (original)
+++ incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/FixedSizeByteBufferAllocatorImpl.java Fri Mar  2 13:00:54 2012
@@ -21,10 +21,10 @@ package org.apache.directmemory.memory.a
 
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
-import java.util.HashSet;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.Queue;
-import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
@@ -42,7 +42,7 @@ public class FixedSizeByteBufferAllocato
 {
 
     // Collection that keeps track of the parent buffers (segments) where slices are allocated
-    private final Set<ByteBuffer> segmentsBuffers = new HashSet<ByteBuffer>();
+    private final List<ByteBuffer> segmentsBuffers;
 
     // Collection that owns all slices that can be used.
     private final Queue<ByteBuffer> freeBuffers = new ConcurrentLinkedQueue<ByteBuffer>();
@@ -77,6 +77,8 @@ public class FixedSizeByteBufferAllocato
         this.totalSize = totalSize;
         this.sliceSize = sliceSize;
 
+        this.segmentsBuffers = new ArrayList<ByteBuffer>(numberOfSegments);
+        
         init( numberOfSegments );
 
     }

Modified: incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImpl.java?rev=1296184&r1=1296183&r2=1296184&view=diff
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImpl.java (original)
+++ incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImpl.java Fri Mar  2 13:00:54 2012
@@ -233,6 +233,7 @@ public class MergingByteBufferAllocatorI
                                 linkedBuffer.getBefore().setAfter( returnedLinkedBuffer );
                             }
                             
+                            // Insert the remaining buffer into the structure
                             parentBuffer.clear();
                             parentBuffer.position( linkedBuffer.getOffset() + size );
                             parentBuffer.limit( linkedBuffer.getOffset() + linkedBuffer.getBuffer().capacity() );



Re: svn commit: r1296184 - in /incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator: FixedSizeByteBufferAllocatorImpl.java MergingByteBufferAllocatorImpl.java

Posted by Simone Tripodi <si...@apache.org>.
Salut Benoit!

> Replacing Set by List as size is know and only iteration is performed

yesterday, while driving (! :D) I thought about it and wondered: given
the preconditions, wouldn't be more convenient switching over a pure
array?

At the of the day, it is an internal data structure and won't be
exposed at all...

-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/