Пример #1
0
 public PinnedStruct(T x)
 {
     Value     = x;
     Handle    = GCHandle.Alloc(Value, GCHandleType.Pinned);
     Ptr       = Handle.AddrOfPinnedObject();
     ByteCount = typeof(T).SizeOf();
 }
Пример #2
0
 /// <summary> Return the Address of the String Array. </summary>
 public IntPtr Address()
 {
     if (_PointerArray == null)
     {
         throw new ArgumentException("Memory has not been allocated");
     }
     return(Handle.AddrOfPinnedObject());
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PinnedStructureArray{T}" /> class.
 /// </summary>
 /// <param name="field">
 /// The pinned values as an array of <typeparamref name="T" />
 /// </param>
 /// <param name="overwriteWithZerosOnDispose">
 /// A value indicating whether or not to overwrite the array with default values upon disposal. The default value is
 /// <see langword="false" />.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="field" /> is <see langword="null" />.
 /// </exception>
 public PinnedStructureArray(T[] field, Boolean overwriteWithZerosOnDispose)
     : base(ConcurrencyControlMode.SingleThreadLock)
 {
     OverwriteWithZerosOnDispose = overwriteWithZerosOnDispose;
     Handle  = GCHandle.Alloc(field.RejectIf().IsNull(nameof(field)).TargetArgument, GCHandleType.Pinned);
     Field   = (T[])Handle.Target;
     Length  = field.Length;
     Pointer = Handle.AddrOfPinnedObject();
 }
Пример #4
0
    public void EnqueueRead(bool async)
    {
        ErrorCode error;

        error = (ErrorCode)CL.EnqueueReadBuffer(CommandQueueId, BufferId, !async, new IntPtr(0), new IntPtr(BufferSize),
                                                Handle.AddrOfPinnedObject(), 0, (IntPtr *)IntPtr.Zero.ToPointer(), (IntPtr *)IntPtr.Zero.ToPointer());
        if (error != ErrorCode.Success)
        {
            throw new System.InvalidOperationException(String.Format("Error calling EnqueueReadBuffer: {0}", error));
        }
    }
Пример #5
0
    public CLBuffer(IntPtr contextId, IntPtr commandQueueId, MemFlags memFlags, T[] data)
    {
        CommandQueueId = commandQueueId;
        ErrorCode error = ErrorCode.Success;

        BufferSize = Marshal.SizeOf(typeof(T)) * data.Length;
        Data       = data;
        BufferId   = CL.CreateBuffer(contextId, memFlags, new IntPtr(BufferSize), Handle.AddrOfPinnedObject(), &error);
        if (error != ErrorCode.Success)
        {
            throw new System.InvalidOperationException(String.Format("Error calling CreateBuffer: {0}", error));
        }
    }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DirectBitmap"/> class with the specified size.
 /// </summary>
 /// <param name="width">The width, in pixels, of the <see cref="DirectBitmap"/>.</param>
 /// <param name="height">The height, in pixels, of the <see cref="DirectBitmap"/>.</param>
 public DirectBitmap(int width, int height)
 {
     Width  = width;
     Height = height;
     Pixels = new int[width * height];
     Handle = GCHandle.Alloc(Pixels, GCHandleType.Pinned);
     Bitmap = new Bitmap(
         width,
         height,
         width * 4,
         PixelFormat.Format32bppPArgb,
         Handle.AddrOfPinnedObject()
         );
 }
Пример #7
0
 public IntPtr AddrOfPinnedObject()
 {
     return(Handle.AddrOfPinnedObject());
 }