/// An array of length <see cref="Dimensions"/> indicating the shape of the memory as an n-dimensional array.
/// </summary>
publiclong[]?Shape{get;privateset;}
/// <summary>
/// An array of length <see cref="Dimensions"/> giving the number of bytes to skip to get to a new element in each dimension.
/// Will be null except when PyBUF_STRIDES or PyBUF_INDIRECT flags in GetBuffer/>.
/// </summary>
publiclong[]?Strides{get;privateset;}
/// <summary>
/// An array of Py_ssize_t of length ndim. If suboffsets[n] >= 0,
/// the values stored along the nth dimension are pointers and the suboffset value dictates how many bytes to add to each pointer after de-referencing.
/// A suboffset value that is negative indicates that no de-referencing should occur (striding in a contiguous memory block).
/// Returns true if the memory defined by the view is C-style (order is 'C') or Fortran-style (order is 'F') contiguous or either one (order is 'A'). Returns false otherwise.
/// </summary>
/// <param name="order">C-style (order is 'C') or Fortran-style (order is 'F') contiguous or either one (order is 'A')</param>
/// Copy len bytes from view to its contiguous representation in buf. order can be 'C' or 'F' or 'A' (for C-style or Fortran-style ordering or either one). 0 is returned on success, -1 on error.
/// </summary>
/// <param name="order">order can be 'C' or 'F' or 'A' (for C-style or Fortran-style ordering or either one).</param>
/// Fill the strides array with byte-strides of a contiguous (C-style if order is 'C' or Fortran-style if order is 'F') array of the given shape with the given number of bytes per element.
/// Handle buffer requests for an exporter that wants to expose buf of size len with writability set according to readonly. buf is interpreted as a sequence of unsigned bytes.
/// The flags argument indicates the request type. This function always fills in view as specified by flags, unless buf has been designated as read-only and PyBUF_WRITABLE is set in flags.
/// On success, set view->obj to a new reference to exporter and return 0. Otherwise, raise PyExc_BufferError, set view->obj to NULL and return -1;
/// If this function is used as part of a getbufferproc, exporter MUST be set to the exporting object and flags must be passed unmodified.Otherwise, exporter MUST be NULL.
/// </remarks>
/// <returns>On success, set view->obj to a new reference to exporter and return 0. Otherwise, raise PyExc_BufferError, set view->obj to NULL and return -1;</returns>
privatebooldisposedValue=false;// To detect redundant calls
privatevoidDispose(booldisposing)
{
if(!disposedValue)
{
if(Runtime.Py_IsInitialized()==0)
thrownewInvalidOperationException("Python runtime must be initialized");
// this also decrements ref count for _view->obj
Runtime.PyBuffer_Release(ref_view);
_exporter=null!;
Shape=null;
Strides=null;
SubOffsets=null;
disposedValue=true;
}
}
~PyBuffer()
{
Debug.Assert(!disposedValue);
if(_view.obj!=IntPtr.Zero)
{
Finalizer.Instance.AddFinalizedBuffer(ref_view);
}
Dispose(false);
}
/// <summary>
/// Release the buffer view and decrement the reference count for view->obj. This function MUST be called when the buffer is no longer being used, otherwise reference leaks may occur.
/// It is an error to call this function on a buffer that was not obtained via <see cref="PyObject.GetBuffer"/>.