Skip to content

Add accessor methods to shared_resource<T> #7313

@bdice

Description

@bdice

Feature Request: Add accessor methods to shared_resource<T>

Problem

shared_resource<T> currently provides no way to access the underlying T object. Unlike shared_ptr<T> which offers operator-> and .get(), shared_resource<T> has no equivalent accessors.

Motivating Use Case

In the RMM Python/Cython layer, a Cython object like StatisticsResourceAdaptor holds a C++ member c_obj of type shared_resource<statistics_resource_adaptor>.

  • Shared ownership is required because the underlying memory resource is stateful
  • Access to methods of statistics_resource_adaptor is needed to retrieve current statistics

Without accessors, the RMM Python/Cython layer cannot be cleanly implemented.

Proposed Solution

Add smart-pointer-like accessors:

Method Return Type Description
operator-> T* Pointer access to underlying resource
operator* T& Reference to underlying resource
.get() T& Named accessor returning reference

Note: .get() returns T& rather than T* (unlike shared_ptr::get()) because shared_resource cannot be in a null state.

Alternatives Considered

  • T& underlying_resource(): A single named accessor. Rejected in favor of the more familiar smart-pointer interface, though functionally equivalent.

Additional Context

We would like this feature to be backported to branch/3.2.x for adoption in RMM 26.04.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions