-
Notifications
You must be signed in to change notification settings - Fork 359
Closed
Description
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_adaptoris 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.
Reactions are currently unavailable