foobar2000 SDK  2015-08-03
Public Types | Public Member Functions | Private Attributes
pfc::bigmem

#include <other.h>

Public Types

enum  { slice = 1024*1024 }
 

Public Member Functions

 bigmem ()
 
 ~bigmem ()
 
size_t _sliceCount ()
 
uint8_t * _slicePtr (size_t which)
 
size_t _sliceSize (size_t which)
 
void clear ()
 
void read (void *ptrOut, size_t bytes, size_t offset)
 
void resize (size_t newSize)
 
size_t size () const
 
void write (const void *ptrIn, size_t bytes, size_t offset)
 

Private Attributes

array_t< uint8_t * > m_data
 
size_t m_size
 

Detailed Description

Definition at line 253 of file other.h.

Member Enumeration Documentation

anonymous enum
Enumerator
slice 

Definition at line 255 of file other.h.

255 {slice = 1024*1024};

Constructor & Destructor Documentation

pfc::bigmem::bigmem ( )
inline

Definition at line 256 of file other.h.

256 : m_size() {}
size_t m_size
Definition: other.h:316
pfc::bigmem::~bigmem ( )
inline

Definition at line 257 of file other.h.

257 {clear();}
void clear()
Definition: other.h:276

Member Function Documentation

size_t pfc::bigmem::_sliceCount ( )
inline

Definition at line 306 of file other.h.

306 {return m_data.get_size();}
array_t< uint8_t * > m_data
Definition: other.h:315
t_size get_size() const
Definition: array.h:130
uint8_t* pfc::bigmem::_slicePtr ( size_t  which)
inline

Definition at line 305 of file other.h.

305 {return m_data[which];}
array_t< uint8_t * > m_data
Definition: other.h:315
size_t pfc::bigmem::_sliceSize ( size_t  which)
inline

Definition at line 307 of file other.h.

307  {
308  if (which + 1 == _sliceCount()) {
309  size_t s = m_size % slice;
310  if (s) return s;
311  }
312  return slice;
313  }
size_t _sliceCount()
Definition: other.h:306
size_t m_size
Definition: other.h:316
void pfc::bigmem::clear ( )
inline

Definition at line 276 of file other.h.

276  {
277  for(size_t walk = 0; walk < m_data.get_size(); ++walk) free(m_data[walk]);
278  m_data.set_size(0);
279  m_size = 0;
280  }
array_t< uint8_t * > m_data
Definition: other.h:315
void set_size(t_size p_size)
Definition: array.h:104
t_size get_size() const
Definition: array.h:130
size_t m_size
Definition: other.h:316
void pfc::bigmem::read ( void *  ptrOut,
size_t  bytes,
size_t  offset 
)
inline

Definition at line 281 of file other.h.

281  {
282  PFC_ASSERT( offset + bytes <= size() );
283  uint8_t * outWalk = (uint8_t*) ptrOut;
284  while(bytes > 0) {
285  size_t o1 = offset / slice, o2 = offset % slice;
286  size_t delta = slice - o2; if (delta > bytes) delta = bytes;
287  memcpy(outWalk, m_data[o1] + o2, delta);
288  offset += delta;
289  bytes -= delta;
290  outWalk += delta;
291  }
292  }
array_t< uint8_t * > m_data
Definition: other.h:315
size_t size() const
Definition: other.h:275
void pfc::bigmem::resize ( size_t  newSize)
inline

Definition at line 259 of file other.h.

259  {
260  clear();
261  m_data.set_size( (newSize + slice - 1) / slice );
262  m_data.fill_null();
263  for(size_t walk = 0; walk < m_data.get_size(); ++walk) {
264  size_t thisSlice = slice;
265  if (walk + 1 == m_data.get_size()) {
266  size_t cut = newSize % slice;
267  if (cut) thisSlice = cut;
268  }
269  void* ptr = malloc(thisSlice);
270  if (ptr == NULL) {clear(); throw std::bad_alloc();}
271  m_data[walk] = (uint8_t*)ptr;
272  }
273  m_size = newSize;
274  }
array_t< uint8_t * > m_data
Definition: other.h:315
void clear()
Definition: other.h:276
void set_size(t_size p_size)
Definition: array.h:104
void fill_null()
Definition: array.h:203
t_size get_size() const
Definition: array.h:130
size_t m_size
Definition: other.h:316
size_t pfc::bigmem::size ( ) const
inline

Definition at line 275 of file other.h.

275 {return m_size;}
size_t m_size
Definition: other.h:316
void pfc::bigmem::write ( const void *  ptrIn,
size_t  bytes,
size_t  offset 
)
inline

Definition at line 293 of file other.h.

293  {
294  PFC_ASSERT( offset + bytes <= size() );
295  const uint8_t * inWalk = (const uint8_t*) ptrIn;
296  while(bytes > 0) {
297  size_t o1 = offset / slice, o2 = offset % slice;
298  size_t delta = slice - o2; if (delta > bytes) delta = bytes;
299  memcpy(m_data[o1] + o2, inWalk, delta);
300  offset += delta;
301  bytes -= delta;
302  inWalk += delta;
303  }
304  }
array_t< uint8_t * > m_data
Definition: other.h:315
size_t size() const
Definition: other.h:275

Field Documentation

array_t<uint8_t*> pfc::bigmem::m_data
private

Definition at line 315 of file other.h.

size_t pfc::bigmem::m_size
private

Definition at line 316 of file other.h.


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