Esempio n. 1
0
        public BlockAllocator TryGet(int size)
        {
            size = AlignToBlock(size);
            BlockAllocator ba = null;

            m_bPool.TryGetValue(size, out ba);
            return(ba);
        }
Esempio n. 2
0
        public BlockAllocator AddPool(int size, int maxnum, bool extendAble = true)
        {
            size = AlignToBlock(size);
            BlockAllocator ba = null;

            if (!m_bPool.TryGetValue(size, out ba))
            {
                ba = new BlockAllocator(size, maxnum, extendAble);
                m_bPool.Add(size, ba);
            }
            return(ba);
        }
Esempio n. 3
0
        public byte[] Allocate(int size)
        {
            size = AlignToBlock(size);
            BlockAllocator allocator = null;

            if (!m_bPool.TryGetValue(size, out allocator))
            {
                allocator = CreateAllocator(size);
                m_bPool.Add(size, allocator);
            }
            return(allocator.Allocate());
        }
Esempio n. 4
0
 public bool Free(ref byte[] p)
 {
     if (p != null)
     {
         BlockAllocator allocator = null;
         try {
             if (m_bPool.TryGetValue(p.Length, out allocator))
             {
                 return(allocator.Free(p));
             }
         } finally {
             p = null;
         }
     }
     return(false);
 }