This commit is contained in:
liming-vie 2016-05-05 21:39:42 +08:00
Родитель 1652b927b5
Коммит 85c9eaba4b
2 изменённых файлов: 5 добавлений и 19 удалений

Просмотреть файл

@ -16,7 +16,6 @@ public:
~FreeList();
char *Pop();
void Push(MemoryBlock*);
void Refer(MemoryBlock*);
private:
MemoryBlock* free_ = nullptr;
size_t size_;
@ -44,8 +43,8 @@ public:
void Refer(char *data);
~Allocator();
inline static Allocator* Get() {
static Allocator allo;
return &allo;
static Allocator allocator_;
return &allocator_;
}
private:
std::unordered_map<size_t, FreeList*> pools_;

Просмотреть файл

@ -33,15 +33,8 @@ inline char* FreeList::Pop() {
inline void FreeList::Push(MemoryBlock*block) {
UNIQLOCK(mutex_);
//if (block->Unlink()) {
block->next = free_;
free_ = block;
//}
}
inline void FreeList::Refer(MemoryBlock*block) {
UNIQLOCK(mutex_);
block->Link();
}
inline MemoryBlock::MemoryBlock(size_t size, FreeList* list) :
@ -49,8 +42,6 @@ next(nullptr) {
data_ = new char[size + header_size_];
*(FreeList**)(data_) = list;
*(MemoryBlock**)(data_ + g_pointer_size) = this;
//*(MemoryBlock**)(data_) = this;
//*(FreeList**)(data_ + g_pointer_size) = list;
}
MemoryBlock::~MemoryBlock() {
@ -58,7 +49,6 @@ MemoryBlock::~MemoryBlock() {
}
inline void MemoryBlock::Unlink() {
//return ((--ref_) == 0);
if ((--ref_) == 0) {
(*(FreeList**)data_)->Push(this);
}
@ -87,17 +77,14 @@ char* Allocator::New(size_t size) {
void Allocator::Free(char *data) {
(*(MemoryBlock**)(data - g_pointer_size))->Unlink();
/* data -= g_pointer_size;
(*(FreeList**)data)->Push(*(MemoryBlock**)(data-g_pointer_size));*/
}
void Allocator::Refer(char *data) {
(*(MemoryBlock**)(data - g_pointer_size))->Link();
/*data -= g_pointer_size;
(*(FreeList**)data)->Refer(*(MemoryBlock**)(data - g_pointer_size));*/
}
Allocator::~Allocator() {
Log::Debug("~Allocator, final pool size: %d\n", pools_.size());
for (auto i : pools_) {
delete i.second;
}