Beispiel #1
0
        internal void FreeChunk(PoolChunk <T> chunk, long handle, SizeClass sizeClass)
        {
            bool mustDestroyChunk;

            lock (this)
            {
                switch (sizeClass)
                {
                case Buffers.SizeClass.Normal:
                    ++this.NumNormalDeallocations;
                    break;

                case Buffers.SizeClass.Small:
                    ++this.NumSmallDeallocations;
                    break;

                case Buffers.SizeClass.Tiny:
                    ++this.NumTinyDeallocations;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                mustDestroyChunk = !chunk.Parent.Free(chunk, handle);
            }
            if (mustDestroyChunk)
            {
                // destroyChunk not need to be called while holding the synchronized lock.
                this.DestroyChunk(chunk);
            }
        }
Beispiel #2
0
        internal void FreeChunk(PoolChunk <T> chunk, long handle, SizeClass sizeClass, bool finalizer)
        {
            bool destroyChunk;

            lock (this)
            {
                if (!finalizer)
                {
                    switch (sizeClass)
                    {
                    case Buffers.SizeClass.Normal:
                        ++_deallocationsNormal;
                        break;

                    case Buffers.SizeClass.Small:
                        ++_deallocationsSmall;
                        break;

                    case Buffers.SizeClass.Tiny:
                        ++_deallocationsTiny;
                        break;

                    default:
                        ThrowHelper.ThrowArgumentOutOfRangeException(); break;
                    }
                }
                destroyChunk = !chunk.Parent.Free(chunk, handle);
            }
            if (destroyChunk)
            {
                // destroyChunk not need to be called while holding the synchronized lock.
                DestroyChunk(chunk);
            }
        }
Beispiel #3
0
        internal void Free(PoolChunk <T> chunk, long handle, int normCapacity, PoolThreadCache <T> cache)
        {
            if (chunk.Unpooled)
            {
                int size = chunk.ChunkSize;
                DestroyChunk(chunk);
                switch (chunk.Origin)
                {
                case PoolChunk <T> .PoolChunkOrigin.UnpooledNormal:
                    Interlocked.Decrement(ref this.deallocationsNormal);
                    break;

                case PoolChunk <T> .PoolChunkOrigin.UnpooledHuge:
                    Interlocked.Add(ref this.activeBytesHuge, -size);
                    Interlocked.Decrement(ref this.deallocationsHuge);
                    break;

                default:
                    throw new InvalidOperationException("Unsupported PoolChunk.Origin: " + chunk.Origin);
                }
            }
            else
            {
                SizeClass sc = this.SizeClass(normCapacity);
                if (cache != null && cache.Add(this, chunk, handle, normCapacity, sc))
                {
                    // cached so not free it.
                    return;
                }

                this.FreeChunk(chunk, handle, sc);
            }
        }
Beispiel #4
0
        private void InsUpdDelSize(char Event, int id)
        {
            var msg = "";

            if (Event == 'I' || Event == 'U')
            {
                var objSize = new SizeClass(id, txtSize.Text);
                msg = BL_Size.InsUpdDelSize(Event, objSize, out id);
            }
            else
            {
                var objSize = new SizeClass(id, "");
                msg = BL_Size.InsUpdDelSize(Event, objSize, out id);
            }

            if (DatabaseMessage.ContainMessage(msg))
            {
                _msgbox.ShowSuccess(msg);
            }
            else
            {
                _msgbox.ShowWarning(msg);
            }
            FillGridview();
            ClearAll();
        }
Beispiel #5
0
        public static List <SizeClass> GetSize(int Event, int id, string code, string code1)
        {
            var lst = new List <SizeClass>();
            var dt  = DlSize.GetSize(Event, id, code, code1);

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    var obj = new SizeClass(Convert.ToInt32(dr["Id"]), dr["Size"].ToString());
                    lst.Add(obj);
                }
            }
            return(lst);
        }
Beispiel #6
0
 static MemoryRegionCache[] CreateSubPageCaches(
     int cacheSize, int numCaches, SizeClass sizeClass)
 {
     if (cacheSize > 0)
     {
         var cache = new MemoryRegionCache[numCaches];
         for (int i = 0; i < cache.Length; i++)
         {
             cache[i] = new SubPageMemoryRegionCache(cacheSize, sizeClass);
         }
         return(cache);
     }
     else
     {
         return(null);
     }
 }
Beispiel #7
0
        MemoryRegionCache Cache(PoolArena <T> area, int normCapacity, SizeClass sizeClass)
        {
            switch (sizeClass)
            {
            case SizeClass.Normal:
                return(CacheForNormal(area, normCapacity));

            case SizeClass.Small:
                return(CacheForSmall(area, normCapacity));

            case SizeClass.Tiny:
                return(CacheForTiny(area, normCapacity));

            default:
                ThrowHelper.ThrowArgumentOutOfRangeException(); return(default);
            }
        }
Beispiel #8
0
        MemoryRegionCache Cache(int normCapacity, SizeClass sizeClass)
        {
            switch (sizeClass)
            {
            case SizeClass.Normal:
                return(this.CacheForNormal(normCapacity));

            case SizeClass.Small:
                return(this.CacheForSmall(normCapacity));

            case SizeClass.Tiny:
                return(this.CacheForTiny(normCapacity));

            default:
                throw new ArgumentOutOfRangeException($"Unknown class {sizeClass}");
            }
        }
Beispiel #9
0
        internal void Free(PoolChunk <T> chunk, long handle, int normCapacity, PoolThreadCache <T> cache)
        {
            if (chunk.Unpooled)
            {
                int size = chunk.ChunkSize;
                this.DestroyChunk(chunk);
                Interlocked.Add(ref this.activeBytesHuge, -size);
                Interlocked.Decrement(ref this.deallocationsHuge);
            }
            else
            {
                SizeClass sc = this.SizeClass(normCapacity);
                if (cache != null && cache.Add(this, chunk, handle, normCapacity, sc))
                {
                    // cached so not free it.
                    return;
                }

                this.FreeChunk(chunk, handle, sc);
            }
        }
Beispiel #10
0
        internal void Free(PoolChunk <T> chunk, long handle, int normCapacity, PoolThreadCache <T> cache)
        {
            if (chunk.Unpooled)
            {
                int size = chunk.ChunkSize;
                DestroyChunk(chunk);
                _ = Interlocked.Add(ref _activeBytesHuge, -size);
                _ = Interlocked.Increment(ref _deallocationsHuge);
            }
            else
            {
                SizeClass sizeClass = SizeClass(normCapacity);
                if (cache is object && cache.Add(this, chunk, handle, normCapacity, sizeClass))
                {
                    // cached so not free it.
                    return;
                }

                FreeChunk(chunk, handle, sizeClass, false);
            }
        }
Beispiel #11
0
 public static string InsUpdDelSize(char Event, SizeClass obj, out int returnId)
 {
     returnId = 0;
     try
     {
         var cmd = new SqlCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = "USP_IUD_tbl_Size_Setup";
         cmd.Connection  = DL_CCommon.ConnectionForCommonDb();
         cmd.Parameters.AddWithValue("@EVENT", Event);
         cmd.Parameters.AddWithValue("@ID", obj.Id);
         cmd.Parameters.AddWithValue("@Size", obj.Size);
         var outparameter = new SqlParameter("@MSG", SqlDbType.NVarChar, 200)
         {
             Direction = ParameterDirection.Output
         };
         cmd.Parameters.Add(outparameter);
         var outId = new SqlParameter("@RETURNOUTID", SqlDbType.NVarChar, 100)
         {
             Direction = ParameterDirection.Output
         };
         cmd.Parameters.Add(outId);
         cmd.ExecuteNonQuery();
         var msg = cmd.Parameters[outparameter.ParameterName].Value;
         returnId = Convert.ToInt32(cmd.Parameters[outId.ParameterName].Value);
         return(Convert.ToString(msg));
     }
     catch (Exception ex)
     {
         throw new ArgumentException(ex.Message);
     }
     finally
     {
         DL_CCommon.ConnectionForCommonDb().Close();
     }
 }
Beispiel #12
0
 protected MemoryRegionCache(int size, SizeClass sizeClass)
 {
     _size      = MathUtil.SafeFindNextPositivePowerOfTwo(size);
     _queue     = PlatformDependent.NewFixedMpscQueue <Entry>(_size);
     _sizeClass = sizeClass;
 }
Beispiel #13
0
    /* Collisions */

    public void setSizeClass(SizeClass newSize)
    {
        size = newSize;
        mass = masses [(int)size];
    }
Beispiel #14
0
 internal SubPageMemoryRegionCache(int size, SizeClass sizeClass)
     : base(size, sizeClass)
 {
 }
Beispiel #15
0
        /// <summary>
        /// Add <see cref="PoolChunk{T}"/> and <paramref name="handle"/> to the cache if there is enough room.
        /// </summary>
        /// <returns><c>true</c> if it fit into the cache <c>false</c> otherwise.</returns>
        internal bool Add(PoolArena <T> area, PoolChunk <T> chunk, long handle, int normCapacity, SizeClass sizeClass)
        {
            MemoryRegionCache cache = Cache(area, normCapacity, sizeClass);

            if (cache is null)
            {
                return(false);
            }
            return(cache.Add(chunk, handle));
        }
Beispiel #16
0
 protected MemoryRegionCache(int size, SizeClass sizeClass)
 {
     this.size      = IntegerExtensions.RoundUpToPowerOfTwo(size);
     this.queue     = new MpscArrayQueue <Entry>(this.size);
     this.sizeClass = sizeClass;
 }
Beispiel #17
0
        ///
        // Add {@link PoolChunk} and {@code handle} to the cache if there is enough room.
        // Returns {@code true} if it fit into the cache {@code false} otherwise.
        //
        internal bool Add(PoolArena <T> area, PoolChunk <T> chunk, long handle, int normCapacity, SizeClass sizeClass)
        {
            MemoryRegionCache c = this.Cache(normCapacity, sizeClass);

            return(c != null && c.Add(chunk, handle));
        }
Beispiel #18
0
 protected MemoryRegionCache(int size, SizeClass sizeClass)
 {
     this.size      = IntegerExtensions.RoundUpToPowerOfTwo(size);
     this.queue     = PlatformDependent.NewFixedMpscQueue <Entry>(this.size);
     this.sizeClass = sizeClass;
 }
Beispiel #19
0
 public static string InsUpdDelSize(char Event, SizeClass obj, out int id)
 {
     id = 0;
     return(DlSize.InsUpdDelSize(Event, obj, out id));
 }