UnmanagedMemoryStream.Initialize Method

Definition

Initializes a new instance of the UnmanagedMemoryStream class in a safe buffer, or by using a pointer to an unmanaged memory location.

Overloads

Initialize(Byte*, Int64, Int64, FileAccess)

Initializes a new instance of the UnmanagedMemoryStream class by using a pointer to an unmanaged memory location.

Initialize(SafeBuffer, Int64, Int64, FileAccess)

Initializes a new instance of the UnmanagedMemoryStream class in a safe buffer with a specified offset, length, and file access.

Initialize(Byte*, Int64, Int64, FileAccess)

Source:
UnmanagedMemoryStream.cs
Source:
UnmanagedMemoryStream.cs
Source:
UnmanagedMemoryStream.cs

Important

This API is not CLS-compliant.

Initializes a new instance of the UnmanagedMemoryStream class by using a pointer to an unmanaged memory location.

C#
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
protected void Initialize(byte* pointer, long length, long capacity, System.IO.FileAccess access);
C#
[System.CLSCompliant(false)]
protected void Initialize(byte* pointer, long length, long capacity, System.IO.FileAccess access);
C#
protected void Initialize(byte* pointer, long length, long capacity, System.IO.FileAccess access);

Parameters

pointer
Byte*

A pointer to an unmanaged memory location.

length
Int64

The length of the memory to use.

capacity
Int64

The total amount of memory assigned to the stream.

access
FileAccess

One of the FileAccess values.

Attributes

Exceptions

The user does not have the required permission.

The pointer value is null.

The length value is less than zero.

-or-

The capacity value is less than zero.

-or-

The length value is large enough to cause an overflow.

Remarks

This method is equivalent to the UnmanagedMemoryStream constructor. It supports methods that need to initialize the pointer before setting stream variables and, therefore, cannot call the parameterized constructor. Such methods should use the parameterless constructor, UnmanagedMemoryStream(), initialize the pointer, and then invoke the Initialize method.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

Initialize(SafeBuffer, Int64, Int64, FileAccess)

Source:
UnmanagedMemoryStream.cs
Source:
UnmanagedMemoryStream.cs
Source:
UnmanagedMemoryStream.cs

Initializes a new instance of the UnmanagedMemoryStream class in a safe buffer with a specified offset, length, and file access.

C#
protected void Initialize(System.Runtime.InteropServices.SafeBuffer buffer, long offset, long length, System.IO.FileAccess access);

Parameters

buffer
SafeBuffer

The buffer to contain the unmanaged memory stream.

offset
Int64

The byte position in the buffer at which to start the unmanaged memory stream.

length
Int64

The length of the unmanaged memory stream.

access
FileAccess

The mode of file access to the unmanaged memory stream.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0