Esempio n. 1
0
        /*public static IntPtr Convert(object value, Func<int, IntPtr> memAlloc, out int bytesAllocated, CharSet charSet = CharSet.Auto, int prefixBytes = 0)
         * {
         *      bytesAllocated = 0;
         *      if (value is null)
         *              return IntPtr.Zero;
         *
         *      var type = value.GetType();
         *
         *      // Handle special cases
         *      if (type.IsArray || type.InheritsFrom(typeof(IEnumerable<>)))
         *      {
         *              var elemType = type.FindElementType();
         *              if (elemType == typeof(string))
         *              {
         *              }
         *              else
         *              {
         *                      var enumType = typeof(IEnumerable<>).MakeGenericType(new[] { elemType });
         *                      var mi = typeof(InteropExtensions).GetMethod("Write", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(IntPtr), enumType, typeof(int), typeof(SizeT) }, null);
         *                      var gmi = mi.MakeGenericMethod(new[] { elemType });
         *                      return gmi.Invoke(null, new object[] { x });
         *              }
         *      }
         *      if (value is IEnumerable)
         *      {
         *              if ()
         *              {
         *
         *              }
         *      }
         *
         *      throw new NotImplementedException();
         * }*/

        /// <summary>Converts the specified pointer to <typeparamref name="T"/>.</summary>
        /// <typeparam name="T">The destination type.</typeparam>
        /// <param name="hMem">A block of allocated memory.</param>
        /// <returns>A value of the type specified.</returns>
        public static T ToType <T>(this SafeAllocatedMemoryHandle hMem)
        {
            if (hMem == null)
            {
                throw new ArgumentNullException(nameof(hMem));
            }
            return(Convert <T>(hMem.DangerousGetHandle(), hMem.Size));
        }
Esempio n. 2
0
 /// <summary>Initializes a new instance of the <see cref="NativeMemoryStream"/> class.</summary>
 /// <param name="memoryAllocator">The memory allocator used to create and extend the native memory.</param>
 /// <param name="addCapacitySize">Size of additional blocks of memory to add when capacity is exceeded.</param>
 /// <param name="maxCapacity">The maximum capacity.</param>
 /// <param name="access">The mode of file access to the native memory stream.</param>
 /// <exception cref="ArgumentNullException">memoryAllocator</exception>
 public NativeMemoryStream(SafeAllocatedMemoryHandle memoryAllocator, long addCapacitySize = DefaultCapacity, long maxCapacity = long.MaxValue, FileAccess access = FileAccess.ReadWrite)
 {
     hmem        = memoryAllocator ?? throw new ArgumentNullException(nameof(memoryAllocator));
     capacity    = memoryAllocator.Size;
     Pointer     = hmem.DangerousGetHandle();
     chunkSize   = addCapacitySize;
     MaxCapacity = maxCapacity;
     this.access = access;
 }
Esempio n. 3
0
 public SafeBufferImpl(SafeAllocatedMemoryHandle hMem) : base(false) => Initialize((ulong)hMem.Size);