Examples of FixedSizeUnsafeAllocator


Examples of org.apache.directmemory.memory.allocator.FixedSizeUnsafeAllocator

    @Test
    public void testInt32Compression()
        throws Exception
    {
        FixedSizeUnsafeAllocator allocator = new FixedSizeUnsafeAllocator( 1, 5 );
        try
        {
            for ( int i = 0; i < 4; i++ )
            {
                int[] values = new int[TEST_VALUES_COUNT];

                Random random = new Random( -System.currentTimeMillis() );
                int min = ( 0x1 << ( i * 8 ) );
                int max = ( 0xFF << ( i * 8 ) );
                for ( int o = 0; o < TEST_VALUES_COUNT; o++ )
                {
                    values[o] = (int) ( random.nextDouble() * ( max - min + 1 ) ) + min;
                }

                MemoryBuffer buffer = allocator.allocate( 5 );

                for ( int v = 0; v < TEST_VALUES_COUNT; v++ )
                {
                    int value = values[v];
                    buffer.clear();
                    buffer.writeCompressedInt( value );
                    checkIntLength( value, buffer.writerIndex() );

                    int result = buffer.readCompressedInt();
                    assertEquals( value, result );
                }
                allocator.free( buffer );
            }
        }
        finally
        {
            allocator.close();
        }
    }
View Full Code Here

Examples of org.apache.directmemory.memory.allocator.FixedSizeUnsafeAllocator

    @Test
    public void testInt64Compression()
        throws Exception
    {

        FixedSizeUnsafeAllocator allocator = new FixedSizeUnsafeAllocator( 1, 9 );
        try
        {
            for ( int i = 0; i < 8; i++ )
            {
                long[] values = new long[TEST_VALUES_COUNT];

                Random random = new Random( -System.currentTimeMillis() );
                int min = ( 0x1 << ( i * 8 ) );
                int max = ( 0xFF << ( i * 8 ) );
                for ( int o = 0; o < TEST_VALUES_COUNT; o++ )
                {
                    values[o] = (long) ( random.nextDouble() * ( max - min + 1 ) ) + min;
                }

                MemoryBuffer buffer = allocator.allocate( 5 );

                for ( int v = 0; v < TEST_VALUES_COUNT; v++ )
                {
                    long value = values[v];
                    buffer.clear();
                    buffer.writeCompressedLong( value );
                    checkLongLength( value, buffer.writerIndex() );

                    long result = buffer.readCompressedLong();
                    assertEquals( value, result );
                }
                allocator.free( buffer );
            }
        }
        finally
        {
            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.