Sha256: c71daba935da650cbe3ec513ffc78ca14137688831b9412e1d4f75bbef6d6a00

Contents?: true

Size: 918 Bytes

Versions: 17

Compression:

Stored size: 918 Bytes

Contents

#ifndef Rice__Default_Allocation_Strategy__hpp_
#define Rice__Default_Allocation_Strategy__hpp_

#include "detail/ruby.hpp"

/*! \file
 *  \brief Strategies for allocation/deallocation of objects.
 */

namespace Rice
{

template<typename T>
struct Default_Allocation_Strategy
{
  //! Allocate an object using operator new.
  static T * allocate() { return new T; }

  //! Delete obj using the delete operator.
  static void free(T * obj) { delete obj; }
};

template<typename T>
struct Xmalloc_Allocation_Strategy
{
  //! Allocate an array of objects using operator new and xmalloc.
  static T * allocate() { T * obj = static_cast<T *>(::xmalloc(sizeof(T))); new(obj) T; return obj; }

  //! Delete obj by calling the destructor explicitly and calling xfree.
  static void free(T * obj) { obj->~T(); ::xfree(obj); }
};

// TODO: array allocation

} // namespace Rice

#endif // Rice__Default_Allocation_Strategy__hpp_

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
jameskilton-rice-1.2.0 rice/Allocation_Strategies.hpp
rice-jdguyot-1.4.3p1 rice/Allocation_Strategies.hpp
rice-1.4.3 rice/Allocation_Strategies.hpp
wurlinc-rice-1.4.0.4 rice/Allocation_Strategies.hpp
wurlinc-rice-1.4.0.1 rice/Allocation_Strategies.hpp
rice-1.4.2 rice/Allocation_Strategies.hpp
rice-jdguyot-1.4.0.p1 rice/Allocation_Strategies.hpp
rice-jdguyot-1.4.0 rice/Allocation_Strategies.hpp
rice-1.4.0 rice/Allocation_Strategies.hpp
rice-1.3.2 rice/Allocation_Strategies.hpp
rice-1.3.1 rice/Allocation_Strategies.hpp
rice-1.3.0 rice/Allocation_Strategies.hpp
rice-1.2.0 rice/Allocation_Strategies.hpp
rice-1.1.0 rice/Allocation_Strategies.hpp
rice-1.0.2 rice/Allocation_Strategies.hpp
rice-1.0.1 rice/Allocation_Strategies.hpp
rice-1.0.0 rice/Allocation_Strategies.hpp