Baza znanjaIzpitno središče
SLSlovenščina
Izberi jezik13

CKTIS / C#

System.Buffers.ArrayPool: praktična referenca

System.Buffers.ArrayPool: praktična referenca: ArrayPool<T> izposodi polje z dolžino najmanj zahtevane velikosti in zahteva Return.

Različica: .NET API; verified on .NET 10.0.14

Sintaksa

System.Buffers.ArrayPool /* select a documented member or constructor */

ArrayPool izposodi polje z dolžino najmanj zahtevane velikosti in zahteva Return.

Uporabite na kritičnih poteh za zmanjšanje kratkotrajnih dodelitev velikih medpomnilnikov.

Izposojena vsebina morda ni ničelna; polje vrnite v finally in počistite občutljive podatke.

Rent(0) lahko vrne prazno polje; vračilo tujega ali istega polja dvakrat krši pogodbo.

Celoten program dejansko uporabi System.Buffers.ArrayPool; natančno pričakovani stdout je 7.

Primeri

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

var pool = ArrayPool<int>.Shared;
var buffer = pool.Rent(4);
buffer[0] = 7;
Console.WriteLine(buffer[0]);
pool.Return(buffer, clearArray: true);

Rezultat

7

Celoten program dejansko uporabi `System.Buffers.ArrayPool`; natančno pričakovani stdout je `7`.

Viri