CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
System::Buffers::ArrayPool< T > Class Template Referencefinal

Provides a thread-safe pool for reusing managed array instances (ArrayPtr<T>). More...

#include <array_pool.h>

Inherits System::Object.

Public Member Functions

 ArrayPool (int32_t maxArrayLength=1024 *1024, int32_t maxArraysPerBucket=50)
 Creates an ArrayPool instance. More...
 
ArrayPtr< T > Rent (int32_t minimumLength)
 Obtains a buffer that is at least minimumLength long. More...
 
void Return (const ArrayPtr< T > &array, bool clearArray=false)
 Returns a previously rented buffer back to the pool. More...
 
- Public Member Functions inherited from System::Object
 Object ()
 Creates object. Initializes all internal data structures. More...
 
virtual ~Object ()
 Destroys object. Frees all internal data structures. More...
 
 Object (Object const &x)
 Copy constructor. Doesn't copy anything, really, just initializes new object and enables copy constructing subclasses. More...
 
Object & operator= (Object const &x)
 Assignment operator. Doesn't copy anything, really, just initializes new object and enables copy constructing subclasses. More...
 
Object * SharedRefAdded ()
 Increments shared reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
int SharedRefRemovedSafe ()
 Decrements and returns shared reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
int RemovedSharedRefs (int count)
 Decreases shared reference count by specified value. More...
 
Detail::SmartPtrCounter * WeakRefAdded ()
 Increments weak reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
void WeakRefRemoved ()
 Decrements weak reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
Detail::SmartPtrCounter * GetCounter ()
 Gets reference counter data structure associated with the object. More...
 
int SharedCount () const
 Gets current value of shared reference counter. More...
 
void Lock ()
 Implements C# lock() statement locking. Call directly or use LockContext sentry object. More...
 
void Unlock ()
 Implements C# lock() statement unlocking. Call directly or use LockContext sentry object. More...
 
virtual bool Equals (ptr obj)
 Compares objects using C# Object.Equals semantics. More...
 
virtual int32_t GetHashCode () const
 Analog of C# Object.GetHashCode() method. Enables hashing of custom objects. More...
 
virtual String ToString () const
 Analog of C# Object.ToString() method. Enables converting custom objects to string. More...
 
virtual ptr MemberwiseClone () const
 Analog of C# Object.MemberwiseClone() method. Enables cloning custom types. More...
 
virtual const TypeInfo & GetType () const
 Gets actual type of object. Analog of C# System.Object.GetType() call. More...
 
virtual bool Is (const TypeInfo &targetType) const
 Check if object represents an instance of type described by targetType. Analog of C# 'is' operator. More...
 
virtual void SetTemplateWeakPtr (uint32_t argument)
 Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containers to weak mode. More...
 
virtual bool FastCast (const Details::FastRttiBase &helper, void **out_ptr) const
 For internal purposes only. More...
 
template<>
bool ReferenceEquals (String const &str, std::nullptr_t)
 Specialization of Object::ReferenceEquals for case of string and nullptr. More...
 
template<>
bool ReferenceEquals (String const &str1, String const &str2)
 Specialization of Object::ReferenceEquals for case of strings. More...
 

Static Public Member Functions

static SharedPtr< ArrayPool< T > > get_Shared ()
 Retrieves the process-wide shared pool instance. The instance is created lazily on first access and configured with the default options. More...
 
static SharedPtr< ArrayPool< T > > Create (int32_t maxArrayLength, int32_t maxArraysPerBucket)
 Creates a new pool instance with custom configuration options. More...
 
- Static Public Member Functions inherited from System::Object
static bool ReferenceEquals (ptr const &objA, ptr const &objB)
 Compares objects by reference. More...
 
template<typename T >
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, T const &objB)
 Compares objects by reference. More...
 
template<typename T >
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, std::nullptr_t)
 Reference-compares value type object with nullptr. More...
 
template<typename T1 , typename T2 >
static std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 Compares reference type objects in C# style. More...
 
template<typename T1 , typename T2 >
static std::enable_if<!IsSmartPtr< T1 >::value &&!IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 Compares value type objects in C# style. More...
 
static const TypeInfo & Type ()
 Implements C# typeof(System.Object) construct. More...
 
template<>
bool Equals (float const &objA, float const &objB)
 Emulates C#-style floating point comparison where two NaNs are considered equal even though according to IEC 60559:1989 NaN is not equal to any value, including NaN. More...
 
template<>
bool Equals (double const &objA, double const &objB)
 Emulates C#-style floating point comparison where two NaNs are considered equal even though according to IEC 60559:1989 NaN is not equal to any value, including NaN. More...
 

Additional Inherited Members

- Public Types inherited from System::Object
typedef SmartPtr< Object > ptr
 Alias for smart pointer type. More...
 

Detailed Description

template<typename T>
class System::Buffers::ArrayPool< T >

Provides a thread-safe pool for reusing managed array instances (ArrayPtr<T>).

Template Parameters
TThe type of elements held by pooled arrays.

Constructor & Destructor Documentation

◆ ArrayPool()

template<typename T >
System::Buffers::ArrayPool< T >::ArrayPool ( int32_t  maxArrayLength = 1024 * 1024,
int32_t  maxArraysPerBucket = 50 
)
inlineexplicit

Creates an ArrayPool instance.

Parameters
maxArrayLengthUpper bound of array lengths kept in this pool.
maxArraysPerBucketMaximum number of kept arrays in a single bucket.
Exceptions
ArgumentOutOfRangeExceptionif any argument is not positive.

Member Function Documentation

◆ Create()

template<typename T >
static SharedPtr< ArrayPool< T > > System::Buffers::ArrayPool< T >::Create ( int32_t  maxArrayLength,
int32_t  maxArraysPerBucket 
)
inlinestatic

Creates a new pool instance with custom configuration options.

Parameters
maxArrayLengthThe maximum array length that may be pooled.
maxArraysPerBucketThe maximum number of arrays kept in each bucket.
Returns
An ArrayPool with the specified configuration.

◆ get_Shared()

template<typename T >
static SharedPtr< ArrayPool< T > > System::Buffers::ArrayPool< T >::get_Shared ( )
inlinestatic

Retrieves the process-wide shared pool instance. The instance is created lazily on first access and configured with the default options.

Returns
A shared pool with the default configuration.

◆ Rent()

template<typename T >
ArrayPtr< T > System::Buffers::ArrayPool< T >::Rent ( int32_t  minimumLength)
inline

Obtains a buffer that is at least minimumLength long.

◆ Return()

template<typename T >
void System::Buffers::ArrayPool< T >::Return ( const ArrayPtr< T > &  array,
bool  clearArray = false 
)
inline

Returns a previously rented buffer back to the pool.

Parameters
arrayThe buffer obtained previously from Rent().
clearArrayIf true, the buffer contents are cleared before pooling.
Note
Arrays whose length does not match this pool's configuration (e.g. those that were allocated by Rent() beyond m_maxArrayLength, or come from another pool) are not pooled and are simply released by the reference counting / GC mechanism.