foobar2000 SDK  2015-01-14
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 245 of file other.h.

Member Enumeration Documentation

anonymous enum
Enumerator
slice 

Definition at line 247 of file other.h.

247 {slice = 1024*1024};

Constructor & Destructor Documentation

pfc::bigmem::bigmem ( )
inline

Definition at line 248 of file other.h.

248 : m_size() {}
size_t m_size
Definition: other.h:308
pfc::bigmem::~bigmem ( )
inline

Definition at line 249 of file other.h.

249 {clear();}
void clear()
Definition: other.h:268

Member Function Documentation

size_t pfc::bigmem::_sliceCount ( )
inline

Definition at line 298 of file other.h.

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

Definition at line 297 of file other.h.

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

Definition at line 299 of file other.h.

299  {
300  if (which + 1 == _sliceCount()) {
301  size_t s = m_size % slice;
302  if (s) return s;
303  }
304  return slice;
305  }
size_t _sliceCount()
Definition: other.h:298
size_t m_size
Definition: other.h:308
void pfc::bigmem::clear ( )
inline

Definition at line 268 of file other.h.

268  {
269  for(size_t walk = 0; walk < m_data.get_size(); ++walk) free(m_data[walk]);
270  m_data.set_size(0);
271  m_size = 0;
272  }
array_t< uint8_t * > m_data
Definition: other.h:307
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:308
void pfc::bigmem::read ( void *  ptrOut,
size_t  bytes,
size_t  offset 
)
inline

Definition at line 273 of file other.h.

273  {
274  PFC_ASSERT( offset + bytes <= size() );
275  uint8_t * outWalk = (uint8_t*) ptrOut;
276  while(bytes > 0) {
277  size_t o1 = offset / slice, o2 = offset % slice;
278  size_t delta = slice - o2; if (delta > bytes) delta = bytes;
279  memcpy(outWalk, m_data[o1] + o2, delta);
280  offset += delta;
281  bytes -= delta;
282  outWalk += delta;
283  }
284  }
array_t< uint8_t * > m_data
Definition: other.h:307
size_t size() const
Definition: other.h:267
void pfc::bigmem::resize ( size_t  newSize)
inline

Definition at line 251 of file other.h.

251  {
252  clear();
253  m_data.set_size( (newSize + slice - 1) / slice );
254  m_data.fill_null();
255  for(size_t walk = 0; walk < m_data.get_size(); ++walk) {
256  size_t thisSlice = slice;
257  if (walk + 1 == m_data.get_size()) {
258  size_t cut = newSize % slice;
259  if (cut) thisSlice = cut;
260  }
261  void* ptr = malloc(thisSlice);
262  if (ptr == NULL) {clear(); throw std::bad_alloc();}
263  m_data[walk] = (uint8_t*)ptr;
264  }
265  m_size = newSize;
266  }
array_t< uint8_t * > m_data
Definition: other.h:307
void clear()
Definition: other.h:268
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:308
size_t pfc::bigmem::size ( ) const
inline

Definition at line 267 of file other.h.

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

Definition at line 285 of file other.h.

285  {
286  PFC_ASSERT( offset + bytes <= size() );
287  const uint8_t * inWalk = (const uint8_t*) ptrIn;
288  while(bytes > 0) {
289  size_t o1 = offset / slice, o2 = offset % slice;
290  size_t delta = slice - o2; if (delta > bytes) delta = bytes;
291  memcpy(m_data[o1] + o2, inWalk, delta);
292  offset += delta;
293  bytes -= delta;
294  inWalk += delta;
295  }
296  }
array_t< uint8_t * > m_data
Definition: other.h:307
size_t size() const
Definition: other.h:267

Field Documentation

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

Definition at line 307 of file other.h.

size_t pfc::bigmem::m_size
private

Definition at line 308 of file other.h.


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