foobar2000 SDK  2015-08-03
mem_block_mgr.h
Go to the documentation of this file.
1 #ifndef _MEM_BLOCK_MGR_H_
2 #define _MEM_BLOCK_MGR_H_
3 
4 #error DEPRECATED
5 
6 
7 template<class T>
9 {
10  struct entry
11  {
12  mem_block_t<T> block;
13  bool used;
14  };
15  ptr_list_t<entry> list;
16 public:
17  T * copy(const T* ptr,int size)
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  }
58 
59  void mark_as_free()
60  {
61  int n;
62  for(n=0;n<list.get_count();n++)
63  {
64  list[n]->used = false;
65  }
66  }
67 
68  ~mem_block_manager() {list.delete_all();}
69 };
70 
71 #endif
ptr_list_t< entry > list
Definition: mem_block_mgr.h:15
T * copy(const T *ptr, int size)
Definition: mem_block_mgr.h:17
mem_block_t< T > block
Definition: mem_block_mgr.h:12