6 #ifndef realroot_SOLVE_SBDSLV_MEMORY_LINEAR_ALLOCATOR_HPP
7 #define realroot_SOLVE_SBDSLV_MEMORY_LINEAR_ALLOCATOR_HPP
18 template<
class T,
bool automatic = false>
32 data_t * _chnk_ =
new data_t[ m_csz = nsz ];
40 m_chnk =
new T[ m_csz = nsz ];
47 sz_t
memuse() {
return sizeof(T)*m_csz; };
50 if ( nsz < m_csz )
return;
51 this->_chunkresize_(nsz);
57 if ( m_nalloc + sz > m_csz )
60 while ( ncsz < m_nalloc + sz ) ncsz *= 2;
63 m_nalloc = m_nalloc + sz;
67 inline void free( sz_t sz ) {
72 inline void dec ( sz_t sz ) {
free(sz); };
74 void free() { m_nalloc = m_csz = 0;
if ( m_chnk )
delete[]
m_chnk; m_chnk = 0; };
76 inline T *
data( sz_t address,
const automatic_dispatch<false>& )
const
78 if ( address >= m_nalloc ) std::cout << address <<
"/" << m_nalloc << std::endl;
80 return m_chnk + address;
83 inline T *
data( sz_t address,
const automatic_dispatch<true> & )
85 if ( address < m_nalloc )
return m_chnk+address;
86 alloc( address + 1 - m_nalloc );
87 return m_chnk + address;
89 inline T *
data( sz_t address )
const {
return data(address,automatic_dispatch<automatic>()); };
unsigned sz_t
Definition: system_linear_allocator.h:22
linear_allocator(unsigned n=0)
Definition: system_linear_allocator.h:90
static const sz_t block
Definition: system_linear_allocator.h:45
sz_t m_nalloc
Definition: system_linear_allocator.h:26
T data_t
Definition: system_linear_allocator.h:21
MP swap(const MP &P, int var_i, int var_j)
Definition: sparse_monomials.hpp:988
T * data(sz_t address, const automatic_dispatch< true > &)
Definition: system_linear_allocator.h:83
void _chnkresize_(sz_t nsz)
Definition: system_linear_allocator.h:28
void free()
Definition: system_linear_allocator.h:74
Definition: system_linear_allocator.h:23
Definition: system_linear_allocator.h:19
TMPL void copy(Polynomial &r, const Polynomial &a)
Copy of a in r.
Definition: sparse_monomials.hpp:613
sz_t alloc(sz_t sz)
Definition: system_linear_allocator.h:54
T * data(sz_t address, const automatic_dispatch< false > &) const
Definition: system_linear_allocator.h:76
void free(sz_t sz)
Definition: system_linear_allocator.h:67
void dec(sz_t sz)
Definition: system_linear_allocator.h:72
sz_t memuse()
Definition: system_linear_allocator.h:47
void reserve(sz_t nsz)
Definition: system_linear_allocator.h:48
T * data(sz_t address) const
Definition: system_linear_allocator.h:89
sz_t m_csz
Definition: system_linear_allocator.h:25
~linear_allocator()
Definition: system_linear_allocator.h:94
Interval< T, r > max(const Interval< T, r > &a, const Interval< T, r > &b)
Definition: Interval_fcts.hpp:135
data_t * m_chnk
Definition: system_linear_allocator.h:24
#define assert(expr, msg)
Definition: shared_object.hpp:57