foobar2000 SDK  2015-01-14
Public Types | Public Member Functions | Static Private Member Functions | Private Attributes
pfc::mem_block_aligned< alignBytes >

#include <memalign.h>

Public Types

typedef mem_block_aligned< alignBytes > self_t
 

Public Member Functions

 mem_block_aligned ()
 
 mem_block_aligned (self_t const &other)
 
 mem_block_aligned (self_t &&other)
 
 ~mem_block_aligned ()
 
void assign (self_t const &other)
 
void * get_ptr ()
 
const void * get_ptr () const
 
size_t get_size () const
 
self_t const & operator= (self_t const &other)
 
self_t const & operator= (self_t &&other)
 
void * ptr ()
 
const void * ptr () const
 
void resize (size_t s)
 
void set_size (size_t s)
 
size_t size () const
 

Static Private Member Functions

static void _free (void *ptr)
 

Private Attributes

void * m_ptr
 
size_t m_size
 

Detailed Description

template<unsigned alignBytes = 16>
class pfc::mem_block_aligned< alignBytes >

Definition at line 7 of file memalign.h.

Member Typedef Documentation

template<unsigned alignBytes = 16>
typedef mem_block_aligned<alignBytes> pfc::mem_block_aligned< alignBytes >::self_t

Definition at line 9 of file memalign.h.

Constructor & Destructor Documentation

template<unsigned alignBytes = 16>
pfc::mem_block_aligned< alignBytes >::mem_block_aligned ( )
inline

Definition at line 10 of file memalign.h.

10 : m_ptr(), m_size() {}
template<unsigned alignBytes = 16>
pfc::mem_block_aligned< alignBytes >::~mem_block_aligned ( )
inline

Definition at line 48 of file memalign.h.

48  {
49  _free(m_ptr);
50  }
static void _free(void *ptr)
Definition: memalign.h:77
template<unsigned alignBytes = 16>
pfc::mem_block_aligned< alignBytes >::mem_block_aligned ( self_t const &  other)
inline

Definition at line 56 of file memalign.h.

56  : m_ptr(), m_size() {
57  assign(other);
58  }
void assign(self_t const &other)
Definition: memalign.h:59
template<unsigned alignBytes = 16>
pfc::mem_block_aligned< alignBytes >::mem_block_aligned ( self_t &&  other)
inline

Definition at line 63 of file memalign.h.

63  {
64  m_ptr = other.m_ptr;
65  m_size = other.m_size;
66  other.m_ptr = NULL; other.m_size = 0;
67  }

Member Function Documentation

template<unsigned alignBytes = 16>
static void pfc::mem_block_aligned< alignBytes >::_free ( void *  ptr)
inlinestaticprivate

Definition at line 77 of file memalign.h.

77  {
78 #ifdef _MSC_VER
79  _aligned_free(ptr);
80 #else
81  free(ptr);
82 #endif
83  }
template<unsigned alignBytes = 16>
void pfc::mem_block_aligned< alignBytes >::assign ( self_t const &  other)
inline

Definition at line 59 of file memalign.h.

59  {
60  resize(other.size());
61  memcpy(ptr(), other.ptr(), size());
62  }
size_t size() const
Definition: memalign.h:16
void resize(size_t s)
Definition: memalign.h:19
template<unsigned alignBytes = 16>
void* pfc::mem_block_aligned< alignBytes >::get_ptr ( )
inline

Definition at line 14 of file memalign.h.

14 {return m_ptr;}
template<unsigned alignBytes = 16>
const void* pfc::mem_block_aligned< alignBytes >::get_ptr ( ) const
inline

Definition at line 15 of file memalign.h.

15 {return m_ptr;}
template<unsigned alignBytes = 16>
size_t pfc::mem_block_aligned< alignBytes >::get_size ( ) const
inline

Definition at line 17 of file memalign.h.

17 {return m_size;}
template<unsigned alignBytes = 16>
self_t const& pfc::mem_block_aligned< alignBytes >::operator= ( self_t const &  other)
inline

Definition at line 52 of file memalign.h.

52  {
53  assign(other);
54  return *this;
55  }
void assign(self_t const &other)
Definition: memalign.h:59
template<unsigned alignBytes = 16>
self_t const& pfc::mem_block_aligned< alignBytes >::operator= ( self_t &&  other)
inline

Definition at line 68 of file memalign.h.

68  {
69  _free(m_ptr);
70  m_ptr = other.m_ptr;
71  m_size = other.m_size;
72  other.m_ptr = NULL; other.m_size = 0;
73  return *this;
74  }
static void _free(void *ptr)
Definition: memalign.h:77
template<unsigned alignBytes = 16>
void* pfc::mem_block_aligned< alignBytes >::ptr ( )
inline

Definition at line 12 of file memalign.h.

12 {return m_ptr;}
template<unsigned alignBytes = 16>
const void* pfc::mem_block_aligned< alignBytes >::ptr ( ) const
inline

Definition at line 13 of file memalign.h.

13 {return m_ptr;}
template<unsigned alignBytes = 16>
void pfc::mem_block_aligned< alignBytes >::resize ( size_t  s)
inline

Definition at line 19 of file memalign.h.

19  {
20  if (s == m_size) {
21  // nothing to do
22  } else if (s == 0) {
23  _free(m_ptr);
24  m_ptr = NULL;
25  } else {
26  void * ptr;
27 #ifdef _MSC_VER
28  if (m_ptr == NULL) ptr = _aligned_malloc(s, alignBytes);
29  else ptr = _aligned_realloc(m_ptr, s, alignBytes);
30  if ( ptr == NULL ) throw std::bad_alloc();
31 #else
32 #ifdef __ANDROID__
33  if ((ptr = memalign( s, alignBytes )) == NULL) throw std::bad_alloc();
34 #else
35  if (posix_memalign( &ptr, alignBytes, s ) < 0) throw std::bad_alloc();
36 #endif
37  if (m_ptr != NULL) {
38  memcpy( ptr, m_ptr, min_t<size_t>( m_size, s ) );
39  _free( m_ptr );
40  }
41 #endif
42  m_ptr = ptr;
43  }
44  m_size = s;
45  }
static void _free(void *ptr)
Definition: memalign.h:77
template<unsigned alignBytes = 16>
void pfc::mem_block_aligned< alignBytes >::set_size ( size_t  s)
inline

Definition at line 46 of file memalign.h.

46 {resize(s);}
void resize(size_t s)
Definition: memalign.h:19
template<unsigned alignBytes = 16>
size_t pfc::mem_block_aligned< alignBytes >::size ( ) const
inline

Definition at line 16 of file memalign.h.

16 {return m_size;}

Field Documentation

template<unsigned alignBytes = 16>
void* pfc::mem_block_aligned< alignBytes >::m_ptr
private

Definition at line 85 of file memalign.h.

template<unsigned alignBytes = 16>
size_t pfc::mem_block_aligned< alignBytes >::m_size
private

Definition at line 86 of file memalign.h.


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