Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ WriteCore()

unsafe void System.IO.UnmanagedMemoryStream.WriteCore ( ReadOnlySpan< byte > buffer)
inlinepackageinherited

Definition at line 502 of file UnmanagedMemoryStream.cs.

503 {
506 long num = Interlocked.Read(ref _position);
507 long num2 = Interlocked.Read(ref _length);
508 long num3 = num + buffer.Length;
509 if (num3 < 0)
510 {
511 throw new IOException(SR.IO_StreamTooLong);
512 }
513 if (num3 > _capacity)
514 {
515 throw new NotSupportedException(SR.IO_FixedCapacity);
516 }
517 if (_buffer == null)
518 {
519 if (num > num2)
520 {
521 Buffer.ZeroMemory(_mem + num2, (nuint)(num - num2));
522 }
523 if (num3 > num2)
524 {
525 Interlocked.Exchange(ref _length, num3);
526 }
527 }
528 if (_buffer != null)
529 {
530 long num4 = _capacity - num;
531 if (num4 < buffer.Length)
532 {
533 throw new ArgumentException(SR.Arg_BufferTooSmall);
534 }
535 byte* pointer = null;
536 try
537 {
539 Buffer.Memmove(ref (pointer + num)[_offset], ref MemoryMarshal.GetReference(buffer), (nuint)buffer.Length);
540 }
541 finally
542 {
543 if (pointer != null)
544 {
546 }
547 }
548 }
549 else
550 {
551 Buffer.Memmove(ref _mem[num], ref MemoryMarshal.GetReference(buffer), (nuint)buffer.Length);
552 }
553 Interlocked.Exchange(ref _position, num3);
554 }
unsafe void AcquirePointer(ref byte *pointer)
Definition SafeBuffer.cs:58
static int Exchange(ref int location1, int value)
static long Read(ref long location)

References System.IO.UnmanagedMemoryStream._buffer, System.IO.UnmanagedMemoryStream._capacity, System.IO.UnmanagedMemoryStream._length, System.IO.UnmanagedMemoryStream._mem, System.IO.UnmanagedMemoryStream._offset, System.IO.UnmanagedMemoryStream._position, System.Runtime.InteropServices.SafeBuffer.AcquirePointer(), System.SR.Arg_BufferTooSmall, System.buffer, System.IO.UnmanagedMemoryStream.EnsureNotClosed(), System.IO.UnmanagedMemoryStream.EnsureWriteable(), System.Threading.Interlocked.Exchange(), System.SR.IO_FixedCapacity, System.SR.IO_StreamTooLong, System.Buffer.Memmove(), System.pointer, System.Threading.Interlocked.Read(), System.Runtime.InteropServices.SafeBuffer.ReleasePointer(), and System.Buffer.ZeroMemory().

Referenced by System.IO.UnmanagedMemoryStream.Write(), System.IO.PinnedBufferMemoryStream.Write(), and System.IO.UnmanagedMemoryStream.Write().