Uploaded image for project: 'Apache DirectMemory'
  1. Apache DirectMemory
  2. DIRECTMEMORY-49

MemoryManagerService.update does not reuse the same pointer

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 0.2
    • None
    • None

    Description

      MemoryManagerService.update actually free and store again the payload, which leads to another pointer allocation. This is fine in lots of case, but when the buffer is full, we still want the update to succeed.

      Moreover, update should throw an exception (BufferOverFlowException for example) when the new payload data is bigger than the previous.

      Considering the following test, where I allocate just enough space for 1 object, I store it, and then want to update it content. I could hope this use case succeed, but it's actually not the case

      @Test
      public void testOffHeapMemoryBufferUpdate() {
      		
      	final int NUMBER_OF_OBJECTS = 1;
      	final int BUFFER_SIZE = NUMBER_OF_OBJECTS * 4; // allocate 4 bytes
      	
      	final OffHeapMemoryBuffer offHeapMemoryBuffer = OffHeapMemoryBufferImpl.createNew(BUFFER_SIZE);
      
              // generate 4 random bytes, store, read back and assert
      	final byte[] payload = generateRandomPayload(4);
      	final Pointer pointer = offHeapMemoryBuffer.store(payload);
      	Assert.assertNotNull(pointer);
      	Assert.assertEquals(new String(payload), new String(offHeapMemoryBuffer.retrieve(pointer)));
      	
              // generate another payload, update it, read it and assert.
      	byte[] otherPayload = generateRandomPayload(4);
      	final Pointer otherPointer = offHeapMemoryBuffer.update(pointer, otherPayload);
      	Assert.assertNotNull(otherPointer);
      	Assert.assertEquals(new String(otherPayload), new String(offHeapMemoryBuffer.retrieve(otherPointer)));
      }
      

      Attachments

        Activity

          People

            noctarius Christoph Engelbert
            bperroud Benoit Perroud
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: