Buffer 클래스

정의

기본 형식의 배열을 조작합니다.

public ref class Buffer abstract sealed
public ref class Buffer sealed
public static class Buffer
public sealed class Buffer
[System.Runtime.InteropServices.ComVisible(true)]
public static class Buffer
type Buffer = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type Buffer = class
Public Class Buffer
Public NotInheritable Class Buffer
상속
Buffer
특성

예제

다음 코드 예제에서는 여러 Buffer 클래스 메서드를 사용하는 방법을 보여 줍니다.

// Example of the Buffer class methods.
using namespace System;

// Display the array elements from right to left in hexadecimal.
void DisplayArray( array<short>^arr )
{
   Console::Write( "  arr:" );
   for ( int loopX = arr->Length - 1; loopX >= 0; loopX-- )
      Console::Write( " {0:X4}", arr[ loopX ] );
   Console::WriteLine();
}

int main()
{
   
   // This array is to be modified and displayed.
   array<short>^arr = {258,259,260,261,262,263,264,265,266,267,268,269,270,271};
   Console::WriteLine( "This example of the Buffer class "
   "methods generates the following output.\n"
   "Note: The array is displayed from right to left.\n" );
   Console::WriteLine( "Initial values of array:\n" );
   
   // Display the initial array values and ByteLength.
   DisplayArray( arr );
   Console::WriteLine( "\nBuffer::ByteLength( arr ): {0}", Buffer::ByteLength( arr ) );
   
   // Copy a region of the array; set a byte within the array.
   Console::WriteLine( "\nCall these methods: \n"
   "  Buffer::BlockCopy( arr, 5, arr, 16, 9 ),\n"
   "  Buffer::SetByte( arr, 7, 170 ).\n" );
   Buffer::BlockCopy( arr, 5, arr, 16, 9 );
   Buffer::SetByte( arr, 7, 170 );
   
   // Display the array and a byte within the array.
   Console::WriteLine( "Final values of array:\n" );
   DisplayArray( arr );
   Console::WriteLine( "\nBuffer::GetByte( arr, 26 ): {0}", Buffer::GetByte( arr, 26 ) );
}

/*
This example of the Buffer class methods generates the following output.
Note: The array is displayed from right to left.

Initial values of array:

  arr: 010F 010E 010D 010C 010B 010A 0109 0108 0107 0106 0105 0104 0103 0102

Buffer::ByteLength( arr ): 28

Call these methods:
  Buffer::BlockCopy( arr, 5, arr, 16, 9 ),
  Buffer::SetByte( arr, 7, 170 ).

Final values of array:

  arr: 010F 0101 0801 0701 0601 0501 0109 0108 0107 0106 AA05 0104 0103 0102

Buffer::GetByte( arr, 26 ): 15
*/
// Example of the Buffer class methods.
using System;

class BufferClassDemo
{
    // Display the array elements from right to left in hexadecimal.
    public static void DisplayArray( short[ ] arr )
    {
        Console.Write( "  arr:" );
        for( int loopX = arr.Length - 1; loopX >= 0; loopX-- )
            Console.Write( " {0:X4}", arr[ loopX ] );
        Console.WriteLine( );
    }

    public static void Main( )
    {
        // This array is to be modified and displayed.
        short[ ] arr = { 258, 259, 260, 261, 262, 263, 264,
                         265, 266, 267, 268, 269, 270, 271 };

        Console.WriteLine( "This example of the Buffer class " +
            "methods generates the following output.\n" +
            "Note: The array is displayed from right to left.\n" );
        Console.WriteLine( "Initial values of array:\n" );

        // Display the initial array values and ByteLength.
        DisplayArray( arr );
        Console.WriteLine( "\nBuffer.ByteLength( arr ): {0}",
            Buffer.ByteLength( arr ) );

        // Copy a region of the array; set a byte within the array.
        Console.WriteLine( "\nCall these methods: \n" +
            "  Buffer.BlockCopy( arr, 5, arr, 16, 9 ),\n" +
            "  Buffer.SetByte( arr, 7, 170 ).\n" );

        Buffer.BlockCopy( arr, 5, arr, 16, 9 );
        Buffer.SetByte( arr, 7, 170 );

        // Display the array and a byte within the array.
        Console.WriteLine( "Final values of array:\n" );
        DisplayArray( arr );
        Console.WriteLine( "\nBuffer.GetByte( arr, 26 ): {0}",
            Buffer.GetByte( arr, 26 ) );
    }
}

/*
This example of the Buffer class methods generates the following output.
Note: The array is displayed from right to left.

Initial values of array:

  arr: 010F 010E 010D 010C 010B 010A 0109 0108 0107 0106 0105 0104 0103 0102

Buffer.ByteLength( arr ): 28

Call these methods:
  Buffer.BlockCopy( arr, 5, arr, 16, 9 ),
  Buffer.SetByte( arr, 7, 170 ).

Final values of array:

  arr: 010F 0101 0801 0701 0601 0501 0109 0108 0107 0106 AA05 0104 0103 0102

Buffer.GetByte( arr, 26 ): 15
*/
open System

// Display the array elements from right to left in hexadecimal.
let displayArray (arr: int16 []) =
    printf "  arr:"
    for i = arr.Length - 1 downto 0 do
        printf $" {arr[i]:X4}"
    printfn ""

// This array is to be modified and displayed.
let arr = 
    [| 258s; 259s; 260s; 261s; 262s; 263s; 264s
       265s; 266s; 267s; 268s; 269s; 270s; 271s |]

printfn "This example of the Buffer class methods generates the following output.\nNote: The array is displayed from right to left.\n"
printfn "Initial values of array:\n"

// Display the initial array values and ByteLength.
displayArray arr
printfn $"\nBuffer.ByteLength(arr): {Buffer.ByteLength arr}"

// Copy a region of the array; set a byte within the array.
printfn "\nCall these methods: \n  Buffer.BlockCopy(arr, 5, arr, 16, 9),\n  Buffer.SetByte(arr, 7, 170).\n"

Buffer.BlockCopy(arr, 5, arr, 16, 9)
Buffer.SetByte(arr, 7, 170uy)

// Display the array and a byte within the array.
printfn "Final values of array:\n"
displayArray arr
printfn $"\nBuffer.GetByte(arr, 26): {Buffer.GetByte(arr, 26)}"


// This example of the Buffer class methods generates the following output.
// Note: The array is displayed from right to left.
//
// Initial values of array:
//
//   arr: 010F 010E 010D 010C 010B 010A 0109 0108 0107 0106 0105 0104 0103 0102
//
// Buffer.ByteLength(arr): 28
//
// Call these methods:
//   Buffer.BlockCopy(arr, 5, arr, 16, 9),
//   Buffer.SetByte(arr, 7, 170).
//
// Final values of array:
//
//   arr: 010F 0101 0801 0701 0601 0501 0109 0108 0107 0106 AA05 0104 0103 0102
//
// Buffer.GetByte(arr, 26): 15
' Example of the Buffer class methods.
Module BufferClassDemo

    ' Display the array elements from right to left in hexadecimal.
    Sub DisplayArray( arr( ) As Short )

        Console.Write( "  arr:" )
        Dim loopX     As Integer
        For loopX = arr.Length - 1 To 0 Step -1
            Console.Write( " {0:X4}", arr( loopX ) )
        Next loopX
        Console.WriteLine( )
    End Sub

    Sub Main( )

        ' This array is to be modified and displayed.
        Dim arr( ) As Short = { 258, 259, 260, 261, 262, 263, 264, _
                                265, 266, 267, 268, 269, 270, 271 }
        Console.WriteLine( _
            "This example of the Buffer class methods generates " & _
            "the following output." & vbCrLf & "Note: The " & _
            "array is displayed from right to left." & vbCrLf )
        Console.WriteLine( "Initial values of array:" & vbCrLf )

        ' Display the initial array values and ByteLength.
        DisplayArray( arr )
        Console.WriteLine( vbCrLf & _
            "Buffer.ByteLength( arr ): {0}", _
            Buffer.ByteLength( arr ) )

        ' Copy a region of the array; set a byte within the array.
        Console.WriteLine( vbCrLf & _
            "Call these methods: " & vbCrLf & _
            "  Buffer.BlockCopy( arr, 5, arr, 16, 9 )," & vbCrLf & _
            "  Buffer.SetByte( arr, 7, 170 )." & vbCrLf )

        Buffer.BlockCopy( arr, 5, arr, 16, 9 )
        Buffer.SetByte( arr, 7, 170 )

        ' Display the array and a byte within the array.
        Console.WriteLine( "Final values of array:" & vbCrLf )
        DisplayArray( arr )
        Console.WriteLine( vbCrLf & _
            "Buffer.GetByte( arr, 26 ): {0}", _
            Buffer.GetByte( arr, 26 ) )
    End Sub 
End Module 

' This example of the Buffer class methods generates the following output.
' Note: The array is displayed from right to left.
' 
' Initial values of array:
' 
'   arr: 010F 010E 010D 010C 010B 010A 0109 0108 0107 0106 0105 0104 0103 0102
' 
' Buffer.ByteLength( arr ): 28
' 
' Call these methods:
'   Buffer.BlockCopy( arr, 5, arr, 16, 9 ),
'   Buffer.SetByte( arr, 7, 170 ).
' 
' Final values of array:
' 
'   arr: 010F 0101 0801 0701 0601 0501 0109 0108 0107 0106 AA05 0104 0103 0102
' 
' Buffer.GetByte( arr, 26 ): 15

설명

Buffer 는 기본 형식의 배열에만 영향을 줍니다. 이 클래스는 개체에 적용되지 않습니다. 각 기본 형식은 기본 형식과 관련된 동작이나 제한 사항에 관계없이 일련의 바이트로 처리됩니다.

Buffer 는 기본 형식의 한 배열에서 다른 기본 형식 배열로 바이트를 복사하고, 배열에서 바이트를 가져오고, 배열에서 바이트를 설정하고, 배열의 길이를 가져오는 메서드를 제공합니다. 이 클래스는 클래스의 유사한 메서드 System.Array 보다 기본 형식을 조작하는 데 더 나은 성능을 제공합니다.

Buffer는 다음과 같은 기본 형식에 SByteInt64UInt32UInt64Int32IntPtrUInt16DoubleCharSingleByteUIntPtrInt16적용할 수 있습니다. Boolean

메서드

BlockCopy(Array, Int32, Array, Int32, Int32)

특정 오프셋에서 시작하는 소스 배열에서 특정 오프셋에서 시작하는 대상 배열로 지정된 바이트 수를 복사합니다.

ByteLength(Array)

지정된 배열의 바이트 수를 반환합니다.

GetByte(Array, Int32)

지정된 배열의 지정된 위치에 있는 바이트를 검색합니다.

MemoryCopy(Void*, Void*, Int64, Int64)

메모리에 있는 하나의 주소에서 다른 주소에 정수(Long) 값으로 지정된 바이트 수를 복사합니다.

이 API는 CLS 규격이 아닙니다.

MemoryCopy(Void*, Void*, UInt64, UInt64)

메모리에 있는 하나의 주소에서 다른 주소에 부호 없는 정수(Long) 값으로 지정된 바이트 수를 복사합니다.

이 API는 CLS 규격이 아닙니다.

SetByte(Array, Int32, Byte)

지정된 배열의 특정 위치에 있는 바이트에 지정된 값을 할당합니다.

적용 대상