Ejemplo n.º 1
0
        /// <summary>
        /// Resizes this array.
        /// </summary>
        /// <param name="size"></param>
        public void Resize(long size)
        {
            _length = size;

            var arrayCount = (int)System.Math.Ceiling((double)size / _fileElementSize);

            _files = new List <IMemoryMappedFile>(arrayCount);
            if (arrayCount < _files.Count)
            { // decrease files/accessors.
                for (int arrayIdx = (int)arrayCount; arrayIdx < _files.Count; arrayIdx++)
                {
                    _accessors[arrayIdx].Dispose();
                    _accessors[arrayIdx] = null;
                    _files[arrayIdx].Dispose();
                    _files[arrayIdx] = null;
                }
                _files.RemoveRange((int)arrayCount, (int)(_files.Count - arrayCount));
            }
            else
            { // increase files/accessors.
                for (int arrayIdx = _files.Count; arrayIdx < arrayCount; arrayIdx++)
                {
                    var file = _factory.New(_fileSizeBytes);
                    _files.Add(file);
                    _accessors.Add(file.CreateViewAccessor(0, _fileSizeBytes));
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a memory mapped huge array.
        /// </summary>
        /// <param name="factory">The factory to create the memory mapped files.</param>
        /// <param name="size">The size of the array.</param>
        /// <param name="arraySize">The size of an indivdual array block.</param>
        public MemoryMappedHugeArray(MemoryMappedFileFactory factory, long size, long arraySize)
        {
            _factory         = factory;
            _length          = size;
            _fileElementSize = arraySize;
            _elementSize     = NativeMemoryMappedFileFactory.GetSize(typeof(T));
            _fileSizeBytes   = arraySize * _elementSize;

            var arrayCount = (int)System.Math.Ceiling((double)size / _fileElementSize);

            _files     = new List <IMemoryMappedFile>(arrayCount);
            _accessors = new List <IMemoryMappedViewAccessor>(arrayCount);
            for (int arrayIdx = 0; arrayIdx < arrayCount; arrayIdx++)
            {
                var file = _factory.New(_fileSizeBytes);
                _files.Add(file);
                _accessors.Add(file.CreateViewAccessor(0, _fileSizeBytes));
            }
        }