embkernel
 All Classes Functions Variables Typedefs Groups Pages
LibDmem.hpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #ifndef LIB_DMEM_HPP_
7 #define LIB_DMEM_HPP_
8 
9 #include <stddef.h>
10 #include "LibMacros.hpp"
11 
12 class LibDmem {
13 public:
14  LibDmem(void* buffer, size_t size);
15  ~LibDmem();
16 
17  void* alloc(size_t size);
18  void free(void* p);
19  void* resize(void* p, size_t size);
20  void* resizeLeft(void* p, size_t left);
21  size_t getTotalMemory();
22  size_t getFreeMemory();
23  unsigned int getBlockCount();
24 private:
25  typedef struct tagSEGMENT {
26  tagSEGMENT *prev;
27  tagSEGMENT *next;
28  size_t size;
29  uint8_t data[1024];//Size is given for debugger only
30  } SEGMENT;
31 
32  static const int SIZE_OF_CTRL = 12;
33 
34  SEGMENT* mBeginning;
35  size_t mFree;
36  size_t mTotalSize;
37  unsigned int mBlockCount;
38 };
39 
40 #endif /* LIB_DMEM_HPP_ */