public override void Write(ReadOnlySpan <T> value) { var length = value.Length; if (length == 0) { return; } unsafe { fixed(T *pValue = value) { var pData = pValue; var tempCount = length; do { TryAlloc(tempCount); var charsToCopy = tempCount < _available ? tempCount : _available; fixed(T *pDest = _array) { var toCopy = charsToCopy * BufferExtensions.SizeOf <T>(); Buffer.MemoryCopy(pData, pDest + (_array.Length - _available), toCopy, toCopy); } pData += charsToCopy; tempCount -= charsToCopy; _available -= charsToCopy; }while (tempCount > 0); } } }
public UnmanagedMemoryManagerAlloc(int length) { Debug.Assert(length > 0); _length = length; var dataPtr = Marshal.AllocHGlobal(length * BufferExtensions.SizeOf <T>());//the allocated memory is not zero-filled. unsafe { _dataPtr = (T *)dataPtr.ToPointer(); } }