Exemple #1
0
        public Buffer <T> CreateBuffer <T>(MemoryFlags flags, long size, IntPtr hostAddress)
            where T : struct
        {
            if (size < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(size));
            }
            else if (size == 0)
            {
                throw new ArgumentException("Invalid buffer size.", nameof(size));
            }

            if (hostAddress == IntPtr.Zero && (flags & (MemoryFlags.UseHostPointer | MemoryFlags.CopyHostPointer)) != 0)
            {
                throw new ArgumentException("Invalid host address.", nameof(hostAddress));
            }
            if (hostAddress != IntPtr.Zero && (flags & (MemoryFlags.UseHostPointer | MemoryFlags.CopyHostPointer)) == 0)
            {
                throw new ArgumentException("Invalid host address.", nameof(hostAddress));
            }

            BufferSafeHandle handle = UnsafeNativeMethods.CreateBuffer(Handle, flags, (IntPtr)size, hostAddress);

            return(new Buffer <T>(this, handle));
        }
Exemple #2
0
        internal Buffer(Context context, Buffer <T> parent, BufferSafeHandle handle)
            : base(context, handle)
        {
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }

            _parent = parent;
        }
Exemple #3
0
        public Buffer <T> CreateSubBuffer(MemoryFlags flags, BufferRegion regionInfo)
        {
            BufferSafeHandle subBuffer = UnsafeNativeMethods.CreateSubBuffer(Handle, flags, regionInfo);

            return(new Buffer <T>(Context, this, subBuffer));
        }
Exemple #4
0
 internal Buffer(Context context, BufferSafeHandle handle)
     : base(context, handle)
 {
 }