Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

System.Runtime.InteropServices.MemoryMarshal: referencia práctica

System.Runtime.InteropServices.MemoryMarshal: referencia práctica: MemoryMarshal realiza reinterpretaciones de bajo nivel de Span/Memory sin copiar.

Versión: .NET API; verified against .NET 10 reference surface

Sintaxis

System.Runtime.InteropServices.MemoryMarshal /* select a documented member or constructor */

MemoryMarshal realiza reinterpretaciones de bajo nivel de Span/Memory sin copiar.

Úsalo solo con una representación binaria explícita y una disposición de tipos controlada.

Suposiciones erróneas sobre alineación, endianness o referencias rompen la corrección y la seguridad.

AsBytes cambia la longitud a bytes; Cast descarta un resto menor que un elemento completo.

El programa completo usa realmente System.Runtime.InteropServices.MemoryMarshal; su stdout esperado exacto es 4.

Ejemplos

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;

Span<int> numbers = stackalloc[] { 0x01020304 };
var bytes = MemoryMarshal.AsBytes(numbers);
Console.WriteLine(bytes.Length);

Resultado

4

El programa completo usa realmente `System.Runtime.InteropServices.MemoryMarshal`; su stdout esperado exacto es `4`.

Fuentes