remotemono
Public Types | Public Member Functions | List of all members
remotemono::RMonoObjectHandle< RawPtrT > Class Template Reference

#include <RMonoHandle_Def.h>

Inheritance diagram for remotemono::RMonoObjectHandle< RawPtrT >:
Inheritance graph
[legend]
Collaboration diagram for remotemono::RMonoObjectHandle< RawPtrT >:
Collaboration graph
[legend]

Public Types

typedef RMonoHandle< rmono_gchandle, &RMonoObjectHandleDelete, REMOTEMONO_GCHANDLE_INVALID > Base
 
typedef RMonoObjectHandle< RawPtrT > Self
 
typedef RawPtrT RawPtr
 
- Public Types inherited from remotemono::RMonoHandle< rmono_gchandle, &RMonoObjectHandleDelete, REMOTEMONO_GCHANDLE_INVALID >
typedef rmono_gchandle HandleType
 
typedef RMonoHandle< HandleType, deleter, invalidHandle > Self
 

Public Member Functions

 RMonoObjectHandle ()
 
 RMonoObjectHandle (std::nullptr_t)
 
 RMonoObjectHandle (rmono_gchandle gchandle, RMonoAPIBase *mono, bool owned=true)
 
 RMonoObjectHandle (const Self &other)
 
 RMonoObjectHandle (Self &&other)
 
Selfoperator= (const Self &other)
 
Selfoperator= (Self &&other)
 
bool operator== (const Self &other) const
 
bool operator!= (const Self &other) const
 
Self pin () const
 
Self clone () const
 
RawPtr raw () const
 
- Public Member Functions inherited from remotemono::RMonoHandle< rmono_gchandle, &RMonoObjectHandleDelete, REMOTEMONO_GCHANDLE_INVALID >
 RMonoHandle ()
 
 RMonoHandle (std::nullptr_t)
 
 RMonoHandle (HandleType handle, RMonoAPIBase *mono, bool owned)
 
 RMonoHandle (const Self &other)
 
 RMonoHandle (Self &&other)
 
Selfoperator= (const Self &other)
 
Selfoperator= (Self &&other)
 
bool operator== (const Self &other) const
 
bool operator!= (const Self &other) const
 
HandleType operator* () const
 
RMonoAPIBasegetMonoAPI ()
 
bool takeOwnership ()
 
void reset ()
 
bool isValid () const
 
bool isNull () const
 
 operator bool () const
 

Additional Inherited Members

- Protected Attributes inherited from remotemono::RMonoHandle< rmono_gchandle, &RMonoObjectHandleDelete, REMOTEMONO_GCHANDLE_INVALID >
std::shared_ptr< Data > d
 

Detailed Description

template<typename RawPtrT>
class remotemono::RMonoObjectHandle< RawPtrT >

A wrapper around MonoObject* and derived types like MonoString*, MonoException* etc.

This class does not hold the raw remote pointer, but holds a rmono_gchandle (created by mono_gchandle_new()) to it. Storing raw remote pointers to such objects in the local process is dangerous, because these objects are managed by Mono's garbage collector, so they could be deleted at any moment as soon as the remote process itself does not hold references to it anymore. And even if the remote process does still hold a reference to it, the GC is allowed to move the objects in memory at any time. There are only three situations in which it is safe to hold references to such objects in native code:

  1. If the raw pointer to the object is kept in a processor register or on the stack of any Mono-attached thread.
  2. If the object is referenced via a rmono_gchandle obtained through mono_gchandle_new(), instead of via the raw MonoObject*.
  3. The object is referenced via a raw MonoObject* that belongs to a pinned rmono_gchandle. See the 'pinned' parameter of mono_gchandle_new().

The first option can be ruled out for RemoteMono, because we want to keep references in the local process, not just on the remote. The third option should be strongly avoided, because it will very quickly lead to severe performance degradation because the GC can't do its job properly. This is why RemoteMono always keeps references to MonoObject* as rmono_gchandle.

It is possible to get the raw MonoObject* by calling raw(), but note that this is only safe to use if the RMonoObjectHandle has been pinned by calling pin(), and only as long as that pinned RMonoObjectHandle remains valid.

Constructor & Destructor Documentation

◆ RMonoObjectHandle() [1/5]

template<typename RawPtrT >
remotemono::RMonoObjectHandle< RawPtrT >::RMonoObjectHandle ( )
inline

Constructs a null pointer handle.

◆ RMonoObjectHandle() [2/5]

template<typename RawPtrT >
remotemono::RMonoObjectHandle< RawPtrT >::RMonoObjectHandle ( std::nullptr_t  )
inline

Constructs a null pointer handle

◆ RMonoObjectHandle() [3/5]

template<typename RawPtrT >
remotemono::RMonoObjectHandle< RawPtrT >::RMonoObjectHandle ( rmono_gchandle  gchandle,
RMonoAPIBase mono,
bool  owned = true 
)
inline

Constructs an RMonoObjectHandle from a rmono_gchandle.

Parameters
gchandleThe GC handle obtained from the remote process by mono_gchandle_new().
monoThe RMonoAPI instance that the object belongs to
ownedtrue if the handle should own the rmono_gchandle and free it using mono_gchandle_free() when the internal shared pointer expires.

◆ RMonoObjectHandle() [4/5]

template<typename RawPtrT >
remotemono::RMonoObjectHandle< RawPtrT >::RMonoObjectHandle ( const Self other)
inline

Copy constructor.

◆ RMonoObjectHandle() [5/5]

template<typename RawPtrT >
remotemono::RMonoObjectHandle< RawPtrT >::RMonoObjectHandle ( Self &&  other)
inline

Move constructor.

Member Function Documentation

◆ clone()

template<typename RawPtrT >
RMonoObjectHandle< RawPtrT >::Self remotemono::RMonoObjectHandle< RawPtrT >::clone
inline

Return a new RMonoObjectHandle with a separate rmono_gchandle referencing the same raw pointer. The new handle will not be pinned.

◆ operator!=()

template<typename RawPtrT >
bool remotemono::RMonoObjectHandle< RawPtrT >::operator!= ( const Self other) const
inline

Returns true if the two RMonoObjectHandle instances refer to different raw remote pointers.

See also
operator==()

◆ operator=() [1/2]

template<typename RawPtrT >
Self& remotemono::RMonoObjectHandle< RawPtrT >::operator= ( const Self other)
inline

Assignment operator.

◆ operator=() [2/2]

template<typename RawPtrT >
Self& remotemono::RMonoObjectHandle< RawPtrT >::operator= ( Self &&  other)
inline

Move-assignment operator

◆ operator==()

template<typename RawPtrT >
bool remotemono::RMonoObjectHandle< RawPtrT >::operator== ( const Self other) const
inline

Returns true if the two RMonoObjectHandle instances refer to the same raw remote pointer, i.e. the same remote MonoObject. Note that this does not compare the rmono_gchandles: Two different GC handles may refer to the same MonoObject, and this method would return true in those cases.

◆ pin()

template<typename RawPtrT >
RMonoObjectHandle< RawPtrT >::Self remotemono::RMonoObjectHandle< RawPtrT >::pin
inline

Return a new RMonoObjectHandle pointing to the same object that this handle points to, but pinned down.

◆ raw()

template<typename RawPtrT >
RMonoObjectHandle< RawPtrT >::RawPtr remotemono::RMonoObjectHandle< RawPtrT >::raw
inline

Return the raw remote pointer behind this RMonoObjectHandle. This calls mono_gchandle_get_target(). Note that this the raw pointer is only safe to use as long as a pinned GC handle to it exists somewhere.


The documentation for this class was generated from the following files: