TBCI Numerical high perf. C++ Library 2.8.0
tbci_memalloc_cache< T > Struct Template Reference

For specializations of the memory allocator: More...

#include <malloc_cache.h>

Public Member Functions

int find_by_sz (const unsigned ln) const
 Find free slot with right len, starting point for search is free_idx.
void enter (const T *const ptr, const unsigned ln)
 Enter into list of FREE slots.
void free_and_enter (const T *const ptr, const unsigned ln)
void rmv (const unsigned idx)
 Remove from list of FREE slots.
const Tfind_and_rmv (const unsigned sz)
Talloc (const unsigned long)
void dealloc (const T *const, const unsigned long)
void deinit (const int thr)
void init (const int thr)
void smp_init ()
void smp_deinit ()
 tbci_memalloc_cache ()
 ~tbci_memalloc_cache ()

Static Public Member Functions

static void _init (tbci_memalloc_cache< T > *th, const int thr)
static void _deinit (tbci_memalloc_cache< T > *th, const int thr)

Public Attributes

tbci_memalloc_cache_tls< T > * malloc_tls
int nthr

Detailed Description

template<typename T>
struct tbci_memalloc_cache< T >

For specializations of the memory allocator:

  • Freed (dealloced) memory blocks are not actually freed, but kept in a little cache, so an allocation to a block of the same size shortly after will succeed without a call to new/malloc/memalign.
  • This happens often for TBCI and thus helps to speed up operations like assignement.
  • Specialization is only suitable for types that do nothing in their default c'tor, such as all elementary types.

Definition at line 279 of file malloc_cache.h.

Constructor & Destructor Documentation

◆ tbci_memalloc_cache()

template<typename T>
tbci_memalloc_cache< T >::tbci_memalloc_cache ( )
inline

Definition at line 368 of file malloc_cache.h.

References _deinit(), _init(), init(), malloc_tls, nthr, num_threads, smp_init(), and thread_reg_callback().

Referenced by _deinit(), and _init().

◆ ~tbci_memalloc_cache()

template<typename T>
tbci_memalloc_cache< T >::~tbci_memalloc_cache ( )
inline

Definition at line 387 of file malloc_cache.h.

References _deinit(), _init(), deinit(), malloc_tls, smp_deinit(), and thread_dereg_callback().

Member Function Documentation

◆ _deinit()

template<typename T>
void tbci_memalloc_cache< T >::_deinit ( tbci_memalloc_cache< T > * th,
const int thr )
inlinestatic

Definition at line 311 of file malloc_cache.h.

References smp_deinit(), and tbci_memalloc_cache().

Referenced by tbci_memalloc_cache(), and ~tbci_memalloc_cache().

◆ _init()

template<typename T>
void tbci_memalloc_cache< T >::_init ( tbci_memalloc_cache< T > * th,
const int thr )
inlinestatic

Definition at line 297 of file malloc_cache.h.

References malloc_tls, nthr, smp_init(), and tbci_memalloc_cache().

Referenced by tbci_memalloc_cache(), and ~tbci_memalloc_cache().

◆ alloc()

template<typename T>
T * tbci_memalloc_cache< T >::alloc ( const unsigned long sz)
inline

We MAY be thread safe on x86 and x86-64, but not anywhere else

Definition at line 467 of file malloc_cache.h.

References _MC_NEW, alloc(), BCHK, DEBUG_PRINTF3, find_and_rmv(), ismainthread, malloc_tls, T, TBCI_MALLOC_LIMIT, thrno, and UNLIKELY.

Referenced by alloc().

◆ dealloc()

template<typename T>
void tbci_memalloc_cache< T >::dealloc ( const T * const ptr,
const unsigned long sz )
inline

Definition at line 508 of file malloc_cache.h.

References _MC_DELETE, BCHK, CSTD__, dealloc(), free_and_enter(), ismainthread, T, TBCI_MALLOC_LIMIT, and UNLIKELY.

Referenced by dealloc().

◆ deinit()

template<typename T>
void tbci_memalloc_cache< T >::deinit ( const int thr)
inline

◆ enter()

template<typename T>
void tbci_memalloc_cache< T >::enter ( const T *const ptr,
const unsigned ln )
inline

◆ find_and_rmv()

template<typename T>
const T * tbci_memalloc_cache< T >::find_and_rmv ( const unsigned sz)
inline

Definition at line 452 of file malloc_cache.h.

References find_by_sz(), LIKELY, malloc_tls, rmv(), SMP_LOCK, SMP_UNLOCK, T, and thrno.

Referenced by alloc().

◆ find_by_sz()

template<typename T>
int tbci_memalloc_cache< T >::find_by_sz ( const unsigned ln) const
inline

◆ free_and_enter()

template<typename T>
void tbci_memalloc_cache< T >::free_and_enter ( const T *const ptr,
const unsigned ln )
inline

◆ init()

template<typename T>
void tbci_memalloc_cache< T >::init ( const int thr)
inline

◆ rmv()

template<typename T>
void tbci_memalloc_cache< T >::rmv ( const unsigned idx)
inline

Remove from list of FREE slots.

Definition at line 444 of file malloc_cache.h.

References tbci_memalloc_cache_tls< T >::free_idx, tbci_memalloc_cache_tls< T >::free_sz, malloc_tls, and thrno.

Referenced by find_and_rmv().

◆ smp_deinit()

template<typename T>
void tbci_memalloc_cache< T >::smp_deinit ( )
inline

Definition at line 337 of file malloc_cache.h.

References all, CSTD__, deinit(), hit, malloc_tls, miss, nthr, srch, T, and thrno.

Referenced by _deinit(), and ~tbci_memalloc_cache().

◆ smp_init()

template<typename T>
void tbci_memalloc_cache< T >::smp_init ( )
inline

Definition at line 329 of file malloc_cache.h.

References init(), and nthr.

Referenced by _init(), and tbci_memalloc_cache().

Member Data Documentation

◆ malloc_tls

◆ nthr

template<typename T>
int tbci_memalloc_cache< T >::nthr

Definition at line 286 of file malloc_cache.h.

Referenced by _init(), find_by_sz(), init(), smp_deinit(), smp_init(), and tbci_memalloc_cache().


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