#include <cstdio>
#include <malloc.h>
#include "smp.h"


Go to the source code of this file.
Namespaces | |
| namespace | TBCI |
Classes | |
| class | TBCI::tbci_memalloc< T > |
| struct | TBCI::tbci_memalloc_cache_tls< T > |
| struct | TBCI::tbci_memalloc_cache< T > |
For specializations of the memory allocator:
| |
| class | TBCI::tbci_memalloc< double > |
| class | TBCI::tbci_memalloc< doubleptr > |
| class | TBCI::tbci_memalloc< float > |
| class | TBCI::tbci_memalloc< floatptr > |
| class | TBCI::tbci_memalloc< unsigned > |
| class | TBCI::tbci_memalloc< uintptr > |
| class | TBCI::tbci_memalloc< int > |
| class | TBCI::tbci_memalloc< intptr > |
| class | TBCI::tbci_memalloc< unsigned char > |
| class | TBCI::tbci_memalloc< signed char > |
| class | TBCI::tbci_memalloc< charptr > |
| class | TBCI::tbci_memalloc< ucharptr > |
| class | TBCI::tbci_memalloc< long > |
| class | TBCI::tbci_memalloc< longptr > |
| class | TBCI::tbci_memalloc< unsigned long > |
| class | TBCI::tbci_memalloc< ulongptr > |
| class | TBCI::tbci_memalloc< unsigned short > |
| class | TBCI::tbci_memalloc< voidptr > |
Defines | |
| #define | MALLOC_CACHE 1 |
| #define | MALLOC |
| #define | TBCI_MALLOC_LOCK 1 |
| #define | DEBUG_PRINTF1(arg1) do {} while (0) |
| #define | DEBUG_PRINTF2(a1, a2) do {} while (0) |
| #define | DEBUG_PRINTF3(a1, a2, a3) do {} while (0) |
| #define | DEBUG_PRINTF4(a1, a2, a3, a4) do {} while (0) |
| #define | TBCI_MALLOC_POOLSZ 8 |
| #define | TBCI_MALLOC_LIMIT 8192 |
| #define | DUMMY1 |
| #define | DUMMY2(TYPE) |
| #define | DUMMY3(t) |
| #define | FGD2 FGDT |
| #define | MINLINE inline |
| #define | NO_SINGLETON_PUBLIC |
| #define | TBCI_SIMD_ALIGN 16 |
| #define | TBCI_MALLOC_ALIGN_FACT 1 |
| #define | _MC_NEW(T, SZ) new T[SZ] |
| #define | _MC_DELETE(T, PTR) delete[] (T*)PTR |
| #define | SSE_VARS_MAY_BE_UNALIGNED |
| #define | INC(x) ++x; |
| #define | SMP_LOCK |
| SMP locking: The TBCI worker threads don't do memory allocations so the memalloc_cache code does not need to be multithreading safe. | |
| #define | SMP_UNLOCK |
| #define | SPECIALIZE_MEMALLOC_CLASS(TYPE) |
| Allocator specialization macro, subsequently used to specialize the allocator for the elementary types. | |
| #define | SPECIALIZE_MEMALLOC(TYPE) |
| #define | SPECIALIZE_MEMALLOC2(TYPE, SHTP) |
| #define | NEW(t, s) tbci_s_allocator<t>(DUMMY3(t)).alloc(s) |
| #define | TBCIDELETE(t, v, sz) tbci_s_allocator<t>(DUMMY3(t)).dealloc(v, sz) |
| #define | TBCIDELETE_RO(t, v, sz) tbci_s_allocator<t>(DUMMY3(t)).dealloc(v, sz) |
| #define | REALLOC(v, os, t, s) |
Typedefs | |
| typedef double * | TBCI::doubleptr |
| typedef float * | TBCI::floatptr |
| typedef unsigned int * | TBCI::uintptr |
| typedef int * | TBCI::intptr |
| typedef char * | TBCI::charptr |
| typedef unsigned char * | TBCI::ucharptr |
| typedef long * | TBCI::longptr |
| typedef unsigned long * | TBCI::ulongptr |
| typedef void * | TBCI::voidptr |
Functions | |
| template<typename T> | |
| tbci_memalloc< T > & | TBCI::tbci_s_allocator () |
| template<> | |
| tbci_memalloc< double > & | TBCI::tbci_s_allocator< double > () |
| template<> | |
| tbci_memalloc< doubleptr > & | TBCI::tbci_s_allocator< doubleptr > () |
| template<> | |
| tbci_memalloc< float > & | TBCI::tbci_s_allocator< float > () |
| template<> | |
| tbci_memalloc< floatptr > & | TBCI::tbci_s_allocator< floatptr > () |
| template<> | |
| tbci_memalloc< unsigned > & | TBCI::tbci_s_allocator< unsigned > () |
| template<> | |
| tbci_memalloc< uintptr > & | TBCI::tbci_s_allocator< uintptr > () |
| template<> | |
| tbci_memalloc< int > & | TBCI::tbci_s_allocator< int > () |
| template<> | |
| tbci_memalloc< intptr > & | TBCI::tbci_s_allocator< intptr > () |
| template<> | |
| tbci_memalloc< unsigned char > & | TBCI::tbci_s_allocator< unsigned char > () |
| template<> | |
| tbci_memalloc< signed char > & | TBCI::tbci_s_allocator< signed char > () |
| template<> | |
| tbci_memalloc< charptr > & | TBCI::tbci_s_allocator< charptr > () |
| template<> | |
| tbci_memalloc< ucharptr > & | TBCI::tbci_s_allocator< ucharptr > () |
| template<> | |
| tbci_memalloc< long > & | TBCI::tbci_s_allocator< long > () |
| template<> | |
| tbci_memalloc< longptr > & | TBCI::tbci_s_allocator< longptr > () |
| template<> | |
| tbci_memalloc< unsigned long > & | TBCI::tbci_s_allocator< unsigned long > () |
| template<> | |
| tbci_memalloc< ulongptr > & | TBCI::tbci_s_allocator< ulongptr > () |
| template<> | |
| tbci_memalloc< unsigned short > & | TBCI::tbci_s_allocator< unsigned short > () |
| template<> | |
| tbci_memalloc< voidptr > & | TBCI::tbci_s_allocator< voidptr > () |
Variables | |
| struct TBCI::tbci_memalloc_cache_tls | TBCI::aligned |
Definition in file malloc_cache.h.
| #define _MC_DELETE | ( | T, | |||
| PTR | ) | delete[] (T*)PTR |
Definition at line 125 of file malloc_cache.h.
Referenced by TBCI::tbci_memalloc_cache< T >::dealloc(), TBCI::tbci_memalloc_cache< T >::deinit(), and TBCI::tbci_memalloc_cache< T >::free_and_enter().
| #define _MC_NEW | ( | T, | |||
| SZ | ) | new T[SZ] |
Definition at line 124 of file malloc_cache.h.
Referenced by TBCI::tbci_memalloc_cache< T >::alloc().
| #define DEBUG_PRINTF1 | ( | arg1 | ) | do {} while (0) |
Definition at line 54 of file malloc_cache.h.
Referenced by TBCI::tbci_memalloc_cache< T >::deinit(), and TBCI::tbci_memalloc_cache< T >::find_by_sz().
| #define DEBUG_PRINTF2 | ( | a1, | |||
| a2 | ) | do {} while (0) |
Definition at line 55 of file malloc_cache.h.
Referenced by TBCI::tbci_memalloc_cache< T >::find_by_sz().
| #define DEBUG_PRINTF3 | ( | a1, | |||
| a2, | |||||
| a3 | ) | do {} while (0) |
Definition at line 56 of file malloc_cache.h.
Referenced by TBCI::tbci_memalloc_cache< T >::alloc(), and TBCI::tbci_memalloc_cache< T >::deinit().
| #define DEBUG_PRINTF4 | ( | a1, | |||
| a2, | |||||
| a3, | |||||
| a4 | ) | do {} while (0) |
Definition at line 57 of file malloc_cache.h.
Referenced by TBCI::tbci_memalloc_cache< T >::free_and_enter().
| #define DUMMY1 |
Definition at line 74 of file malloc_cache.h.
| #define DUMMY2 | ( | TYPE | ) |
Definition at line 75 of file malloc_cache.h.
| #define DUMMY3 | ( | t | ) |
Definition at line 76 of file malloc_cache.h.
| #define FGD2 FGDT |
Definition at line 77 of file malloc_cache.h.
| #define INC | ( | x | ) | ++x; |
Definition at line 137 of file malloc_cache.h.
| #define MALLOC |
Definition at line 29 of file malloc_cache.h.
| #define MALLOC_CACHE 1 |
Definition at line 14 of file malloc_cache.h.
| #define MINLINE inline |
Definition at line 80 of file malloc_cache.h.
| #define NEW | ( | t, | |||
| s | ) | tbci_s_allocator<t>(DUMMY3(t)).alloc(s) |
Definition at line 627 of file malloc_cache.h.
Referenced by TBCI::BVector< T >::BVector(), TBCI::BVector< unsigned >::BVector(), TBCI::BdMatrix< T >::constructor(), TBCI::TSVector< T >::detach(), TBCI::TSMatrix< T >::detach(), TBCI::F_TSMatrix< T >::detach(), TBCI::eig(), TBCI::BVector< T >::remove(), TBCI::TMatrix< T >::resize(), TBCI::F_TMatrix< T >::resize(), TBCI::BVector< T >::resize(), TBCI::TMatrix< T >::row_expand(), and TBCI::Vector< T >::Vector().
| #define NO_SINGLETON_PUBLIC |
Definition at line 89 of file malloc_cache.h.
| #define REALLOC | ( | v, | |||
| os, | |||||
| t, | |||||
| s | ) |
Value:
do { \ t *ptr = NEW(t, s); \ if (LIKELY(v)) { \ TBCICOPY(ptr, v, t, MIN(os, s));\ TBCIDELETE(t, v, os); \ } \ v = ptr; \ } while (0)
Definition at line 630 of file malloc_cache.h.
Referenced by TBCI::BdMatrix< T >::adddiag(), TBCI::BVector< T >::append(), TBCI::BVector< T >::resize(), and TBCI::TMatrix< T >::row_expand().
| #define SMP_LOCK |
SMP locking: The TBCI worker threads don't do memory allocations so the memalloc_cache code does not need to be multithreading safe.
However, to make the TBCI threading framework more useful, we should allow this in the future.
The current implementation does the following:
Possible future work:
Definition at line 236 of file malloc_cache.h.
Referenced by TBCI::tbci_memalloc_cache< T >::find_and_rmv(), and TBCI::tbci_memalloc_cache< T >::free_and_enter().
| #define SMP_UNLOCK |
Definition at line 237 of file malloc_cache.h.
Referenced by TBCI::tbci_memalloc_cache< T >::find_and_rmv(), and TBCI::tbci_memalloc_cache< T >::free_and_enter().
| #define SPECIALIZE_MEMALLOC | ( | TYPE | ) |
Value:
SPECIALIZE_MEMALLOC_CLASS(TYPE) \ template <> \ MINLINE tbci_memalloc<TYPE >& tbci_s_allocator<TYPE > (DUMMY2(TYPE)) \ { /* the one and only */ \ static tbci_memalloc<TYPE > _tbci_s_alloc_##TYPE; \ return _tbci_s_alloc_##TYPE; \ }
Definition at line 572 of file malloc_cache.h.
| #define SPECIALIZE_MEMALLOC2 | ( | TYPE, | |||
| SHTP | ) |
Value:
SPECIALIZE_MEMALLOC_CLASS(TYPE) \ template <> \ MINLINE tbci_memalloc<TYPE >& tbci_s_allocator<TYPE > (DUMMY2(TYPE)) \ { /* the one and only */ \ static tbci_memalloc<TYPE > _tbci_s_alloc_##SHTP; \ return _tbci_s_alloc_##SHTP; \ }
Definition at line 581 of file malloc_cache.h.
| #define SPECIALIZE_MEMALLOC_CLASS | ( | TYPE | ) |
Value:
template <> \ class tbci_memalloc<TYPE > { \ typedef TYPE T; \ protected: \ tbci_memalloc_cache<T > m_cache; \ NO_SINGLETON_PUBLIC \ tbci_memalloc() {} \ ~tbci_memalloc() {} \ public: \ friend tbci_memalloc<T >& tbci_s_allocator FGD2 (DUMMY1); \ T* alloc(const unsigned long sz) { return m_cache.alloc(sz); } \ void dealloc(const T* const ptr, const unsigned long sz) \ { m_cache.dealloc(ptr,sz); } \ };
Definition at line 543 of file malloc_cache.h.
| #define SSE_VARS_MAY_BE_UNALIGNED |
Definition at line 127 of file malloc_cache.h.
| #define TBCI_MALLOC_ALIGN_FACT 1 |
Definition at line 120 of file malloc_cache.h.
| #define TBCI_MALLOC_LIMIT 8192 |
Definition at line 65 of file malloc_cache.h.
Referenced by TBCI::tbci_memalloc_cache< T >::alloc(), and TBCI::tbci_memalloc_cache< T >::dealloc().
| #define TBCI_MALLOC_LOCK 1 |
Definition at line 37 of file malloc_cache.h.
| #define TBCI_MALLOC_POOLSZ 8 |
Definition at line 62 of file malloc_cache.h.
Referenced by TBCI::tbci_memalloc_cache< T >::deinit(), TBCI::tbci_memalloc_cache< T >::enter(), TBCI::tbci_memalloc_cache< T >::find_by_sz(), and TBCI::tbci_memalloc_cache< floatptr >::init().
| #define TBCI_SIMD_ALIGN 16 |
Definition at line 117 of file malloc_cache.h.
Referenced by do_mat_tsv_mult(), and do_mat_vec_mult().
| #define TBCIDELETE | ( | t, | |||
| v, | |||||
| sz | ) | tbci_s_allocator<t>(DUMMY3(t)).dealloc(v, sz) |
Definition at line 628 of file malloc_cache.h.
Referenced by TBCI::TSVector< T >::clone(), TBCI::TSMatrix< T >::clone(), TBCI::F_TSMatrix< T >::clone(), TBCI::TSVector< T >::destroy(), TBCI::F_TSMatrix< T >::destroy(), TBCI::F_TMatrix< T >::destroy(), TBCI::BVector< T >::destroy(), TBCI::TSMatrix< T >::detach(), TBCI::F_TSMatrix< T >::detach(), TBCI::eig(), TBCI::BdMatrix< T >::free_diags(), TBCI::TSMatrix< T >::real_destroy(), TBCI::TMatrix< T >::real_destroy(), TBCI::BdMatrix< T >::reconfig(), TBCI::BVector< T >::remove(), TBCI::BdMatrix< T >::removediag(), TBCI::TMatrix< T >::resize(), TBCI::F_TMatrix< T >::resize(), TBCI::BVector< T >::resize(), TBCI::BdMatrix< T >::resize(), TBCI::TMatrix< T >::row_expand(), TBCI::TMatrix< T >::set_ptrs(), TBCI::F_TMatrix< T >::set_ptrs(), and TBCI::TVector< T >::slice().
| #define TBCIDELETE_RO | ( | t, | |||
| v, | |||||
| sz | ) | tbci_s_allocator<t>(DUMMY3(t)).dealloc(v, sz) |
Definition at line 629 of file malloc_cache.h.
1.5.6