Exemple #1
0
        /// <summary>
        /// Gets the create accessor function for the given type.
        /// </summary>
        public static CreateAccessorFunc <T> GetCreateAccessorFuncFor <T>()
        {
            var type = typeof(T);

            lock (_accessorDelegates)
            {
                if (_accessorDelegates == null ||
                    _accessorDelegates.Count == 0)
                { // register accessors.
                    MemoryMap.RegisterCreateAccessorFuncs();
                }

                if (!_accessorDelegates.TryGetValue(type, out var value))
                {
                    throw new NotSupportedException(
                              $"Type {type} not supported, try explicitly registering an accessor creating function.");
                }
                return((CreateAccessorFunc <T>)value);
            }
        }
Exemple #2
0
        protected int _elementSize; // The size of a single element.

        /// <summary>
        /// Creates a new mapped accessor.
        /// </summary>
        public MappedAccessor(MemoryMap file, Stream stream, int elementSize)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanSeek)
            {
                throw new ArgumentException("Stream to create a memory mapped file needs to be seekable.");
            }
            if (elementSize == 0 || elementSize < -1)
            {
                throw new ArgumentOutOfRangeException("elementSize need to be -1 or in the range of ]0-n].");
            }

            _file        = file;
            _stream      = stream;
            _elementSize = elementSize;
        }
Exemple #3
0
 /// <summary>
 /// Diposes of all native resources associated with this object.
 /// </summary>
 public virtual void Dispose()
 {
     _file.Disposed <T>(this);
     _file = null;
 }