jaulib v1.3.0
Jau Support Library (C++, Java, ..)
Classes | Public Types | Public Member Functions | List of all members
jau::callocator< T > Struct Template Reference

A simple allocator using POSIX C functions: ::malloc(), ::free() and ::realloc(). More...

#include <callocator.hpp>

Inheritance diagram for jau::callocator< T >:
Collaboration diagram for jau::callocator< T >:

Classes

struct  rebind
 

Public Types

typedef const T * const_pointer
 
typedef const T & const_reference
 
typedef std::ptrdiff_t difference_type
 
typedef std::true_type is_always_equal
 
typedef T * pointer
 
typedef std::true_type propagate_on_container_move_assignment
 
typedef T & reference
 
typedef std::size_t size_type
 
typedef T value_type
 

Public Member Functions

 callocator () noexcept=default
 
 callocator (const callocator &) noexcept
 
template<typename U >
 callocator (const callocator< U > &) noexcept
 
 ~callocator ()=default
 
value_typeallocate (std::size_t n)
 
value_typeallocate (std::size_t n, const void *)
 
void deallocate (value_type *p, std::size_t)
 
constexpr value_typereallocate (value_type *p, std::size_t, std::size_t new_size)
 

Detailed Description

template<class T>
struct jau::callocator< T >

A simple allocator using POSIX C functions: ::malloc(), ::free() and ::realloc().


It is the missing ::realloc() in std::allocator, motivating this class.
Since realloc() requires the passed pointer to originate from malloc() or calloc, we have to use it for allocate() as well.

Added method is reallocate() using the native realloc().

This class shall be compliant with C++ named requirements for Allocator.

Not implementing deprecated (C++17) and removed (C++20) methods: address(), max_size(), construct() and destroy().

Examples
test_cow_darray_perf01.cpp.

Definition at line 49 of file callocator.hpp.

Member Typedef Documentation

◆ value_type

template<class T >
typedef T jau::callocator< T >::value_type

Definition at line 53 of file callocator.hpp.

◆ size_type

template<class T >
typedef std::size_t jau::callocator< T >::size_type

Definition at line 54 of file callocator.hpp.

◆ difference_type

template<class T >
typedef std::ptrdiff_t jau::callocator< T >::difference_type

Definition at line 55 of file callocator.hpp.

◆ propagate_on_container_move_assignment

template<class T >
typedef std::true_type jau::callocator< T >::propagate_on_container_move_assignment

Definition at line 56 of file callocator.hpp.

◆ is_always_equal

template<class T >
typedef std::true_type jau::callocator< T >::is_always_equal

Definition at line 59 of file callocator.hpp.

◆ pointer

template<class T >
typedef T* jau::callocator< T >::pointer

Definition at line 62 of file callocator.hpp.

◆ const_pointer

template<class T >
typedef const T* jau::callocator< T >::const_pointer

Definition at line 63 of file callocator.hpp.

◆ reference

template<class T >
typedef T& jau::callocator< T >::reference

Definition at line 64 of file callocator.hpp.

◆ const_reference

template<class T >
typedef const T& jau::callocator< T >::const_reference

Definition at line 65 of file callocator.hpp.

Constructor & Destructor Documentation

◆ callocator() [1/3]

template<class T >
jau::callocator< T >::callocator ( )
defaultnoexcept

◆ callocator() [2/3]

template<class T >
jau::callocator< T >::callocator ( const callocator< T > &  )
inlinenoexcept

Definition at line 80 of file callocator.hpp.

◆ callocator() [3/3]

template<class T >
template<typename U >
jau::callocator< T >::callocator ( const callocator< U > &  )
inlinenoexcept

Definition at line 90 of file callocator.hpp.

◆ ~callocator()

template<class T >
jau::callocator< T >::~callocator ( )
default

Member Function Documentation

◆ allocate() [1/2]

template<class T >
value_type * jau::callocator< T >::allocate ( std::size_t  n,
const void *   
)
inline

Definition at line 101 of file callocator.hpp.

Here is the caller graph for this function:

◆ allocate() [2/2]

template<class T >
value_type * jau::callocator< T >::allocate ( std::size_t  n)
inline

Definition at line 111 of file callocator.hpp.

◆ reallocate()

template<class T >
constexpr value_type * jau::callocator< T >::reallocate ( value_type p,
std::size_t  ,
std::size_t  new_size 
)
inlineconstexpr

Definition at line 116 of file callocator.hpp.

Here is the caller graph for this function:

◆ deallocate()

template<class T >
void jau::callocator< T >::deallocate ( value_type p,
std::size_t   
)
inline

Definition at line 126 of file callocator.hpp.

Here is the caller graph for this function:

The documentation for this struct was generated from the following file: