Пример #1
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="capacity">容量</param>
 public TriplePinnedByteBuffer(int capacity)
 {
     byteBuffers = new PinnedBuffer <byte>[3] {
         PinnedBuffer <byte> .Alloc(capacity),
         PinnedBuffer <byte> .Alloc(capacity),
         PinnedBuffer <byte> .Alloc(capacity)
     };
 }
Пример #2
0
        /// <summary>
        /// 创建缓冲区
        /// </summary>
        /// <param name="size">缓冲区大小</param>
        /// <returns>缓冲区</returns>
        public static PinnedBuffer <T> Alloc(int size)
        {
            var buffer = new PinnedBuffer <T> {
                buffer = new T[size]
            };

            buffer.handle = GCHandle.Alloc(buffer.buffer, GCHandleType.Pinned);
            buffer.ptr    = buffer.handle.AddrOfPinnedObject();

            return(buffer);
        }