コード例 #1
0
        private int AllocateBlockId()
        {
            var freeBlock = FreeBlocks.Where(b => !InitialFreeBlocks.Contains(b)).FirstOrDefault();

            if (freeBlock == 0)
            {
                freeBlock = FreeBlocks.FirstOrDefault();
            }
            if (freeBlock == 0)
            {
                freeBlock = TailBlockId++;
            }
            FreeBlocks.Remove(freeBlock);
            AllocatedBlocks.Add(freeBlock);
            return(freeBlock);
        }
コード例 #2
0
        /// <summary>
        /// Writes the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>System.Int64.</returns>
        public long Write(string value)
        {
            lock (_writeLock)
            {
                if (BlocksFree <= 0)
                {
                    return(-1);
                }

                var freeBlock = FreeBlocks.First();
                using (var accessor = MapFile.CreateViewAccessor(freeBlock * MaxBlockSize, MaxBlockSize))
                {
                    accessor.WriteArray(0, Encoding.ASCII.GetBytes(value), 0, value.Length);
                }

                FreeBlocks = FreeBlocks.Where(block => !block.Equals(freeBlock)).ToList();
                BlocksFree--;
                Save();
                return(freeBlock);
            }
        }