CentralMine.NET.HashManager.Allocate C# (CSharp) Method

Allocate() public method

public Allocate ( uint desired, Client c ) : HashBlock
desired uint
c Client
return HashBlock
        public HashBlock Allocate(uint desired, Client c)
        {
            HashBlock block = null;

            HashBlock free = FindFreeBlock(desired);
            if (free != null)
            {
                if (free.Count > desired)
                {
                    // Split this block
                    block = new HashBlock();
                    block.Owner = c;
                    block.Start = free.Start;
                    block.Count = desired;
                    mBusyBlocks.Add(block);

                    free.Start += desired;
                    free.Count -= desired;
                }
                else
                {
                    // Remove the free block from the free list
                    mFreeBlocks.Remove(free);

                    // Assign the free block to the client
                    free.Owner = c;

                    // Add the block to the busy list
                    block = free;
                    mBusyBlocks.Add(block);
                }
            }

            return block;
        }