FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
memory_manager.h
1 #ifndef __MEMORY_MANAGER__
2 #define __MEMORY_MANAGER__
3 
4 /*
5  * Copyright 2014 Open Connectome Project (http://openconnecto.me)
6  * Written by Da Zheng (zhengda1936@gmail.com)
7  *
8  * This file is part of SAFSlib.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include <vector>
24 
25 #include "cache.h"
26 #include "slab_allocator.h"
27 
28 namespace safs
29 {
30 
35 class memory_manager: public slab_allocator
36 {
37  std::vector<page_cache *> caches;
38 
39  memory_manager(long max_size, int node_id);
40 
41  ~memory_manager() {
42  // TODO
43  }
44 public:
45  static memory_manager *create(long max_size, int node_id) {
46  assert(node_id >= 0);
47  return new memory_manager(max_size, node_id);
48  }
49 
50  static void destroy(memory_manager *m) {
51  delete m;
52  }
53 
54  void register_cache(page_cache *cache) {
55  caches.push_back(cache);
56  }
57 
58  void unregister_cache(page_cache *cache) {
59  // TODO
60  }
61 
62  bool get_free_pages(int npages, char **pages, page_cache *cache);
63  void free_pages(int npages, char **pages);
64 
65  long average_cache_size() {
66  return get_max_size() / caches.size();
67  }
68 };
69 
70 }
71 
72 #endif
Definition: memory_manager.h:35