Пример #1
0
 protected SafeBuffer(int length, params T[] values) : base(IntPtr.Zero, true)
 {
     if (BufferHelpers.IsReferenceOrContainsReferences(typeof(T), out FieldInfo field))
     {
         throw new ArgumentException($"Only structures without reference fields can be used with this class. The field {field.Name} has type {field.FieldType.Name}.");
     }
     if (values.Length > length)
     {
         throw new ArgumentException("The length of the list of values must be smaller or equal to the length of the buffer");
     }
     SizeInBytes = NotAllocated;
     base.SetHandle(Allocate(length));
     if (IsAllocated)
     {
         CopyFrom(values);
     }
 }
Пример #2
0
        protected HugeBuffer(ulong length, params T[] values) : base(IntPtr.Zero, true)
        {
            ulong l = (ulong)values.Length;

            if (BufferHelpers.IsReferenceOrContainsReferences <T>())
            {
                throw new ArgumentException("Only structures without reference fields can be used with this class.");
            }
            if (l > length)
            {
                throw new ArgumentException("The length of the list of values must be smaller or equal to the length of the buffer");
            }
            SizeInBytes = NotAllocated;
            base.SetHandle(Allocate(length));
            if (IsAllocated)
            {
                CopyFrom(values);
            }
        }
Пример #3
0
 protected SafeBuffer(int length, params T[] values) : base(IntPtr.Zero, true)
 {
     if (BufferHelpers.IsReferenceOrContainsReferences <T>())
     {
         throw new ArgumentException("Only structures without reference fields can be used with this class.");
     }
     if (values.Length > length)
     {
         throw new ArgumentException("The length of the list of values must be smaller or equal to the length of the buffer");
     }
     SizeInBytes = NotAllocated;
     base.SetHandle(Allocate(length));
     if (IsAllocated)
     {
         for (int i = 0; i < values.Length; i++)
         {
             this[i] = values[i];
         }
     }
 }