/// <summary>实例化一个内存集合</summary>
        /// <param name="mf">内存文件</param>
        /// <param name="offset">内存偏移</param>
        /// <param name="size">内存大小。为0时自动增长</param>
        public MemoryCollection(MemoryFile mf, Int64 offset, Int64 size)
        {
            if (offset == 0 && size == 0)
            {
                View = mf.CreateView();
                size = View.Capacity;
            }
            else
            {
                View = mf.CreateView(offset, size);
            }

            // 根据视图大小计算出可存储对象个数
            var n = size - _HeadSize;

            Capacity = (Int32)(n / _ItemSize);
        }
示例#2
0
        /// <summary>实例化数据堆</summary>
        /// <param name="mf"></param>
        /// <param name="offset"></param>
        /// <param name="size"></param>
        /// <param name="init">自动初始化</param>
        public Heap(MemoryFile mf, Int64 offset = 0, Int64 size = 0, Boolean init = true)
        {
            if (mf == null)
            {
                throw new ArgumentNullException(nameof(mf));
            }
            // 内存映射未初始化时 mf.Capacity=0
            //if (offset < 0 || offset >= mf.Capacity && mf.Capacity > 0) throw new ArgumentOutOfRangeException(nameof(offset));
            //if (size < 0) size = mf.Capacity - offset;

            Position = offset;
            Size     = size;
            View     = mf.CreateView(offset, size);

            if (init)
            {
                Init();
            }
        }
示例#3
0
        /// <summary>实例化数据库</summary>
        /// <param name="file">文件</param>
        /// <param name="readOnly">只读</param>
        /// <param name="init">自动初始化</param>
        public ListDb(String file, Boolean readOnly, Boolean init = true)
        {
            File     = new MemoryFile(file, readOnly);
            ReadOnly = readOnly;

            if (readOnly)
            {
                View = File.CreateView(HEADER_SIZE, MAX_SIZE);
            }
            else
            {
                Heap = new Heap(File, HEADER_SIZE, MAX_SIZE, false);
                View = Heap.View;
            }

            // 加大步进增长率,减少映射次数,提升性能
            //View.StepRate = 100;

            // 加载
            if (init)
            {
                Init();
            }
        }