| 4 | #include "os_type.h" |
| 5 | |
| 6 | class BitMap |
| 7 | { |
| 8 | public: |
| 9 | // 被管理的资源个数,bitmap的总位数 |
| 10 | int length; |
| 11 | // bitmap的起始地址 |
| 12 | char *bitmap; |
| 13 | public: |
| 14 | // 初始化 |
| 15 | BitMap(); |
| 16 | // 设置BitMap,bitmap=起始地址,length=总位数(即被管理的资源个数) |
| 17 | void initialize(char *bitmap, const int length); |
| 18 | // 获取第index个资源的状态,true=allocated,false=free |
| 19 | bool get(const int index) const; |
| 20 | // 设置第index个资源的状态,true=allocated,false=free |
| 21 | void set(const int index, const bool status); |
| 22 | // 分配count个连续的资源,若没有则返回-1,否则返回分配的第1个资源单元序号 |
| 23 | int allocate(const int count); |
| 24 | // 释放第index个资源开始的count个资源 |
| 25 | void release(const int index, const int count); |
| 26 | // 返回Bitmap存储区域 |
| 27 | char *getBitmap(); |
| 28 | // 返回Bitmap的大小 |
| 29 | int size() const; |
| 30 | private: |
| 31 | // 禁止Bitmap之间的赋值 |
| 32 | BitMap(const BitMap &) {} |
| 33 | void operator=(const BitMap&) {} |
| 34 | }; |
| 35 | |
| 36 | #endif |
nothing calls this directly
no outgoing calls
no test coverage detected