Skip to content

Add GC.IsPinnedHeapObject(object obj) API #33542

@VSadov

Description

@VSadov

GC.IsPinnedHeapObject(object obj)

Returns true if the obj is allocated on pinned object heap.

Caveat: we generally cannot know cheaply/precisely if object is pinned (thus this is not a IsPinnedObject), but we can tell if it resides in Pinned Object Heap.

===

There are obvious scenarios where this could be useful.
When trying to use pinned object heap in prototypes, it does not take long before you want to write code like:

if (GC.IsPinnedHeapObject(obj))
{
    .. something simple that relies on obj not relocating ..
}
else
{
   .. pinning by hand for compat or throw something, if this is unexpected...
}

or do something like:

Debug.Assert(GC.IsPinnedHeapObject(buffer), "buffer must be on pinned heap");

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-GC-coreclr

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions