Example #1
0
        protected internal OffHeapNumberArray(long length, int itemSize, long @base, MemoryAllocationTracker allocationTracker) : base(itemSize, @base)
        {
            UnsafeUtil.assertHasUnsafe();
            this.LengthConflict    = length;
            this.AllocationTracker = allocationTracker;

            long dataSize             = length * itemSize;
            bool itemSizeIsPowerOfTwo = Integer.bitCount(itemSize) == 1;

            if (UnsafeUtil.allowUnalignedMemoryAccess || !itemSizeIsPowerOfTwo)
            {
                // we can end up here even if we require aligned memory access. Reason is that item size
                // isn't power of two anyway and so we have to fallback to safer means of accessing the memory,
                // i.e. byte for byte.
                _allocatedBytes        = dataSize;
                this._allocatedAddress = this.Address = UnsafeUtil.allocateMemory(_allocatedBytes, allocationTracker);
            }
            else
            {
                // the item size is a power of two and we're required to access memory aligned
                // so we can allocate a bit more to ensure we can get an aligned memory address to start from.
                _allocatedBytes        = dataSize + itemSize - 1;
                this._allocatedAddress = UnsafeUtil.allocateMemory(_allocatedBytes, allocationTracker);
                this.Address           = UnsafeUtil.alignedMemory(_allocatedAddress, itemSize);
            }
        }
Example #2
0
 internal static long GetVictimPage(int pageSize, MemoryAllocationTracker allocationTracker)
 {
     lock (typeof(VictimPageReference))
     {
         if (_victimPageSize < pageSize)
         {
             // Note that we NEVER free any old victim pages. This is important because we cannot tell
             // when we are done using them. Therefor, victim pages are allocated and stay allocated
             // until our process terminates.
             _victimPagePointer = UnsafeUtil.allocateMemory(pageSize, allocationTracker);
             _victimPageSize    = pageSize;
         }
         return(_victimPagePointer);
     }
 }
Example #3
0
        public override void Clear()
        {
            if (IsByteUniform(_defaultValue))
            {
                UnsafeUtil.setMemory(Address, LengthConflict * itemSize, _defaultValue[0]);
            }
            else
            {
                long intermediary = UnsafeUtil.allocateMemory(itemSize, AllocationTracker);
                for (int i = 0; i < _defaultValue.Length; i++)
                {
                    UnsafeUtil.putByte(intermediary + i, _defaultValue[i]);
                }

                for (long i = 0, adr = Address; i < LengthConflict; i++, adr += itemSize)
                {
                    UnsafeUtil.copyMemory(intermediary, adr, itemSize);
                }
                UnsafeUtil.free(intermediary, itemSize, AllocationTracker);
            }
        }