Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Auto release objects

Jonathan Beard edited this page Jun 29, 2020 · 1 revision

Autorelease objects

These objects are returned from some port calls with the intent of providing zero copy for larger allocations that would otherwise have to be copied from the port. They also provide iterator abstractions for items returned.

IMPORTANT - when these objects pass out of scope or destruct, they perform an action. The pop/peek_range variants remote the elements from the target port and free them. The allocate variant automatically pushes data to the destination port. These are conveniences that could also be replicated by calling functions directly.

Useful functions

These operators vary by autorelease specialization

Basic pop-type

Operator * overload

   /**
    * *operator - dereference this auto-release objec to 
    * get the actual value (by reference).
    * @return T&
    */
   const T& operator *() const noexcept
   {
      return( item );
   }

Range type

Array index overload

 autopair< T > operator []( const std::size_t index )

This returns an autopair object that contains

template < class T > struct autopair
{
   autopair( T &ele, Buffer::Signal &sig ) : ele( ele ),
                                             sig( sig )
   {}

   T              &ele;
   Buffer::Signal &sig;
};

So that the programmer can access each element directly while having less ability to corrupt or accidentally free the underlying memory.

  /**
    * getindex - returns index for foreach constructs,
    * future versions will deprecate this for all types
    * but that one.
    */
   std::size_t getindex() noexcept
   {
      return( signal[ 0 ] .getindex() );
   }
   /**
    * size - returns the size of the given autorelease object
    */
   std::size_t size() noexcept
   {
      return( n_items );
   }
Clone this wiki locally