Beispiel #1
0
 /// <summary>
 /// Helper method to create a new memory mapped file.
 /// </summary>
 /// <returns></returns>
 private IMemoryMappedFile CreateNew()
 {
     if (!string.IsNullOrEmpty(_path))
     {
         return(NativeMemoryMappedFileFactory.CreateFromFile(_path + System.Guid.NewGuid().ToString(), _fileSizeBytes));
     }
     return(NativeMemoryMappedFileFactory.CreateNew(System.Guid.NewGuid().ToString(), _fileSizeBytes));
 }
        /// <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));
            }
        }