Examples of MemoryBuffer


Examples of org.apache.directmemory.memory.buffer.MemoryBuffer

    {
        Random rnd = new Random();
        int size = rnd.nextInt( 10 ) * (int) MemoryManager.capacity() / 100;
        logger.info( "payload size=" + Ram.inKb( size ) );
        Pointer<Object> p = MemoryManager.allocate( size );
        MemoryBuffer b = p.getMemoryBuffer();
        logger.info( "allocated" );
        assertNotNull( p );
        assertNotNull( b );

        // assertTrue( b.isDirect() );
        assertEquals( 0, b.readerIndex() );
        assertEquals( size, b.capacity() );

        byte[] check = MemoryManager.retrieve( p );

        assertNotNull( check );

View Full Code Here

Examples of org.apache.directmemory.memory.buffer.MemoryBuffer

        throws IOException
    {

        Allocator allocator = new MergingByteBufferAllocator( 0, 5000 );

        MemoryBuffer bf1 = allocator.allocate( 250 );
        Assert.assertEquals( 250, bf1.maxCapacity() );
        Assert.assertEquals( 250, bf1.capacity() );

        MemoryBuffer bf2 = allocator.allocate( 251 );
        Assert.assertEquals( 251, bf2.maxCapacity() );
        Assert.assertEquals( 251, bf2.capacity() );

        MemoryBuffer bf3 = allocator.allocate( 200 );
        Assert.assertEquals( 200, bf3.maxCapacity() );
        Assert.assertEquals( 200, bf3.capacity() );

        MemoryBuffer bf4 = allocator.allocate( 2000 );
        Assert.assertEquals( 2000, bf4.maxCapacity() );
        Assert.assertEquals( 2000, bf4.capacity() );

        MemoryBuffer bf5 = allocator.allocate( 2001 );
        Assert.assertEquals( 2001, bf5.maxCapacity() );
        Assert.assertEquals( 2001, bf5.capacity() );

        MemoryBuffer bf6 = allocator.allocate( 298 );
        Assert.assertEquals( 298, bf6.maxCapacity() );
        Assert.assertEquals( 298, bf6.capacity() );

        MemoryBuffer bf7 = allocator.allocate( 128 );
        Assert.assertNull( bf7 );

        allocator.close();
    }
View Full Code Here

Examples of org.apache.directmemory.memory.buffer.MemoryBuffer

        throws IOException
    {

        Allocator allocator = new MergingByteBufferAllocator( 0, 1000 );

        MemoryBuffer bf1 = allocator.allocate( 250 );
        Assert.assertEquals( 250, bf1.maxCapacity() );
        Assert.assertEquals( 250, bf1.capacity() );

        MemoryBuffer bf2 = allocator.allocate( 251 );
        Assert.assertEquals( 251, bf2.maxCapacity() );
        Assert.assertEquals( 251, bf2.capacity() );

        MemoryBuffer bf3 = allocator.allocate( 252 );
        Assert.assertEquals( 252, bf3.maxCapacity() );
        Assert.assertEquals( 252, bf3.capacity() );

        MemoryBuffer bf4 = allocator.allocate( 500 );
        Assert.assertNull( bf4 );

        allocator.free( bf1 );
        allocator.free( bf2 );

        MemoryBuffer bf5 = allocator.allocate( 500 );
        Assert.assertEquals( 501, bf5.maxCapacity() );
        Assert.assertEquals( 500, bf5.capacity() );

        allocator.close();
    }
View Full Code Here

Examples of org.apache.directmemory.memory.buffer.MemoryBuffer

        Allocator allocator = new MergingByteBufferAllocator( 0, 1000 );

        for ( int i = 0; i < 1000; i++ )
        {
            MemoryBuffer bf1 = allocator.allocate( 250 );
            Assert.assertEquals( 250, bf1.maxCapacity() );
            Assert.assertEquals( 250, bf1.capacity() );

            allocator.free( bf1 );
        }

        MemoryBuffer bf2 = allocator.allocate( 1000 );
        Assert.assertEquals( 1000, bf2.maxCapacity() );
        Assert.assertEquals( 1000, bf2.capacity() );

        allocator.close();
    }
View Full Code Here

Examples of org.apache.directmemory.memory.buffer.MemoryBuffer

        throws IOException
    {

        Allocator allocator = new MergingByteBufferAllocator( 0, 200 );

        MemoryBuffer bf1 = allocator.allocate( 180 );
        Assert.assertEquals( 200, bf1.maxCapacity() );
        Assert.assertEquals( 180, bf1.capacity() );

        MemoryBuffer bf2 = allocator.allocate( 5 );
        Assert.assertNull( bf2 );

        allocator.free( bf1 );

        MemoryBuffer bf3 = allocator.allocate( 10 );
        Assert.assertEquals( 10, bf3.maxCapacity() );
        Assert.assertEquals( 10, bf3.capacity() );

        MemoryBuffer bf4 = allocator.allocate( 20 );
        Assert.assertEquals( 20, bf4.maxCapacity() );
        Assert.assertEquals( 20, bf4.capacity() );

        MemoryBuffer bf5 = allocator.allocate( 30 );
        Assert.assertEquals( 30, bf5.maxCapacity() );
        Assert.assertEquals( 30, bf5.capacity() );

        allocator.free( bf4 );
        allocator.free( bf3 );

        MemoryBuffer bf6 = allocator.allocate( 25 );
        Assert.assertEquals( 30, bf6.maxCapacity() );
        Assert.assertEquals( 25, bf6.capacity() );

        allocator.close();
    }
View Full Code Here

Examples of org.apache.directmemory.memory.buffer.MemoryBuffer

        MergingByteBufferAllocator allocator = new MergingByteBufferAllocator( 0, 200 );
        allocator.setSizeRatioThreshold( 0.95 );

        allocator.setSizeRatioThreshold( 10 );

        MemoryBuffer bf1 = allocator.allocate( 180 );
        Assert.assertEquals( 180, bf1.maxCapacity() );
        Assert.assertEquals( 180, bf1.capacity() );

        MemoryBuffer bf2 = allocator.allocate( 10 );
        Assert.assertEquals( 20, bf2.maxCapacity() );
        Assert.assertEquals( 10, bf2.capacity() );

        allocator.close();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.