Esempio n. 1
0
        // Primary constructor
        //
        internal DirectByteBuffer(int cap) : base(-1, 0, cap, cap)         // package-private
        {
            bool pa   = VM.DirectMemoryPageAligned;
            int  ps   = Bits.PageSize();
            long size = System.Math.Max(1L, (long)cap + (pa ? ps : 0));

            Bits.ReserveMemory(size, cap);

            long @base = 0;

            try
            {
                @base = @unsafe.allocateMemory(size);
            }
            catch (OutOfMemoryError x)
            {
                Bits.UnreserveMemory(size, cap);
                throw x;
            }
            @unsafe.setMemory(@base, size, (sbyte)0);
            if (pa && (@base % ps != 0))
            {
                // Round up to page boundary
                Address = @base + ps - (@base & (ps - 1));
            }
            else
            {
                Address = @base;
            }
            Cleaner_Renamed = Cleaner.create(this, new Deallocator(@base, size, cap));
            Att             = null;
        }