foobar2000 SDK  2015-01-14
Data Structures | Public Member Functions | Private Attributes
mem_block_manager< T >

#include <mem_block_mgr.h>

Data Structures

struct  entry
 

Public Member Functions

 ~mem_block_manager ()
 
Tcopy (const T *ptr, int size)
 
void mark_as_free ()
 

Private Attributes

ptr_list_t< entrylist
 

Detailed Description

template<class T>
class mem_block_manager< T >

Definition at line 8 of file mem_block_mgr.h.


Data Structure Documentation

struct mem_block_manager::entry

template<class T>
struct mem_block_manager< T >::entry

Definition at line 10 of file mem_block_mgr.h.

Data Fields
mem_block_t< T > block
bool used

Constructor & Destructor Documentation

template<class T >
mem_block_manager< T >::~mem_block_manager ( )
inline

Definition at line 68 of file mem_block_mgr.h.

68 {list.delete_all();}
ptr_list_t< entry > list
Definition: mem_block_mgr.h:15

Member Function Documentation

template<class T >
T* mem_block_manager< T >::copy ( const T ptr,
int  size 
)
inline

Definition at line 17 of file mem_block_mgr.h.

18  {
19  int n;
20  int found_size = -1,found_index = -1;
21  for(n=0;n<list.get_count();n++)
22  {
23  if (!list[n]->used)
24  {
25  int block_size = list[n]->block.get_size();
26  if (found_size<0)
27  {
28  found_index=n; found_size = block_size;
29  }
30  else if (found_size<size)
31  {
32  if (block_size>found_size)
33  {
34  found_index=n; found_size = block_size;
35  }
36  }
37  else if (found_size>size)
38  {
39  if (block_size>=size && block_size<found_size)
40  {
41  found_index=n; found_size = block_size;
42  }
43  }
44 
45  if (found_size==size) break;
46  }
47  }
48  if (found_index>=0)
49  {
50  list[found_index]->used = true;
51  return list[found_index]->block.copy(ptr,size);
52  }
53  entry * new_entry = new entry;
54  new_entry->used = true;
55  list.add_item(new_entry);
56  return new_entry->block.copy(ptr,size);
57  }
ptr_list_t< entry > list
Definition: mem_block_mgr.h:15
template<class T >
void mem_block_manager< T >::mark_as_free ( )
inline

Definition at line 59 of file mem_block_mgr.h.

60  {
61  int n;
62  for(n=0;n<list.get_count();n++)
63  {
64  list[n]->used = false;
65  }
66  }
ptr_list_t< entry > list
Definition: mem_block_mgr.h:15

Field Documentation

template<class T >
ptr_list_t<entry> mem_block_manager< T >::list
private

Definition at line 15 of file mem_block_mgr.h.


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