Skip to content

Need to pull pinning via &MemoryMarshal.GetReference #27308

Closed
@JeremyKuhne

Description

@JeremyKuhne

C# 7.3 allows pinning spans directly. Pinning empty behaves differently than pinning the ref returned from MemoryMarshal.GetReference.

static unsafe void PinMe()
{
    int[] emptyArray = new int[0];
    Span<int> emptySpan = new Span<int>(emptyArray);
    fixed (int* ea = emptyArray)
    fixed (int* es = emptySpan)
    fixed (int* esr = &MemoryMarshal.GetReference(emptySpan))
    {
        Console.WriteLine($"Array: 0x{(ulong)ea:X}, Span: 0x{(ulong)es:X}, Address of ref span: 0x{(ulong)esr:X}");
    }
}

Yields something like:

Array: 0x0, Span: 0x0, Address of ref span: 0x27D97CD1588

dotnet/corefx#32072 (comment)

cc: @danmosemsft, @jkotas

Metadata

Metadata

Assignees

Labels

area-Metabacklog-cleanup-candidateAn inactive issue that has been marked for automated closure.enhancementProduct code improvement that does NOT require public API changes/additionshelp wanted[up-for-grabs] Good issue for external contributorsno-recent-activitytenet-reliabilityReliability/stability related issue (stress, load problems, etc.)

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions