示例#1
0
 /// <summary>
 /// Writes the specified index.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <param name="value">The value.</param>
 public void Write(long index, string value)
 {
     using (var accessor = MapFile.CreateViewAccessor(index * MaxBlockSize, MaxBlockSize))
     {
         accessor.WriteArray(0, Encoding.ASCII.GetBytes(value), 0, value.Length);
     }
 }
示例#2
0
        /// <summary>
        /// Reads the specified position.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="length">The length.</param>
        /// <returns>System.String.</returns>
        public string Read(long position, long length)
        {
            var data = new byte[length];

            using (var accessor = MapFile.CreateViewAccessor(position * MaxBlockSize, length))
            {
                accessor.ReadArray(0, data, 0, data.Length);
            }
            return(Encoding.ASCII.GetString(data));
        }
示例#3
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);
            }
        }