Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/mscorlib/src/System/IO/FileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,24 @@ public virtual SafeFileHandle SafeFileHandle {
}
}


// This method allows the user to specify an external buffer, which can then be pooled or shared
// among mulitple instances of FileStream. Note that this buffer can _only_ be used by a single
// instance of FileStream at a time.
// This should be called before any action is done on the FileStream, otherwise a buffer will
// be allocation, and we'll miss this optimization
[System.Security.SecuritySafeCritical] // auto-generated
public override void SetBuffer(byte[] externalBuffer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your example, the method is called SetExternalBuffer

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, slip of the keyboard while writing the comment. I think that the name SetBuffer is better, with the externalBuffer name indicating what is going on.

{
if (externalBuffer==null)
throw new ArgumentNullException("externalBuffer", Environment.GetResourceString("ArgumentNull_Buffer"));
if (externalBuffer.Length < _bufferSize)
throw new ArgumentOutOfRangeException("externalBuffer", Environment.GetResourceString("Arg_BufferTooSmall"));
// it is okay to use a buffer that is too big, only _bufferSize is ever used for checking
// and this allows to use a larger buffer in a stream that have a smaller buffer size.
_buffer = externalBuffer;
}

[System.Security.SecuritySafeCritical] // auto-generated
public override void SetLength(long value)
{
Expand Down