Beispiel #1
0
 static TFBuffer()
 {
     //int
     //FreeBufferFunc = Marshal.GetFunctionPointerForDelegate<BufferReleaseFunc> (FreeBlock);
     FreeBlockDelegate = FreeBlock;
     FreeBufferFunc    = Marshal.GetFunctionPointerForDelegate(FreeBlockDelegate);
 }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:TensorFlow.TFBuffer"/> by wrapping the unmanaged resource pointed by the buffer.
        /// </summary>
        /// <param name="buffer">Pointer to the data that will be wrapped.</param>
        /// <param name="size">The size of the buffer to wrap.</param>
        /// <param name="release">Optional, if not null, this method will be invoked to release the block.</param>
        /// <remarks>
        /// This constructor wraps the buffer as a the data to be held by the <see cref="T:TensorFlow.TFBuffer"/>,
        /// if the release parameter is null, then you must ensure that the data is not released before the TFBuffer
        /// is no longer in use.   If the value is not null, the provided method will be invoked to release
        /// the data when the TFBuffer is disposed, or the contents of the buffer replaced.
        /// </remarks>
        unsafe public TFBuffer(IntPtr buffer, long size, BufferReleaseFunc release) : base((IntPtr)TF_NewBuffer())
        {
            LLBuffer *buf = (LLBuffer *)handle;

            buf->data   = buffer;
            buf->length = (size_t)size;
            if (release == null)
            {
                buf->data_deallocator = IntPtr.Zero;
            }
            else
            {
                buf->data_deallocator = Marshal.GetFunctionPointerForDelegate(release);
            }
        }