forked from qdaxb/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslab.h
More file actions
58 lines (57 loc) · 1.14 KB
/
slab.h
File metadata and controls
58 lines (57 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//****************************************************
// Author: Axb - [email protected]
// Create Time: 2013-02-20 08:45
// Filename: slab.h
// Description:
//****************************************************
#ifndef _SLAB_H_
#define _SLAB_H_
#include <list>
#include <stdlib.h>
#include <stdio.h>
#include <typeinfo>
#include "common.h"
using namespace std;
template <class T>
class Slab:public Singleton < Slab<T> >{
public:
using Singleton< Slab<T> >::getInstance;
static int registerSlab()
{
//do nothing
return 0;
}
static int unRegisterSlab()
{
//do nothing
return 0;
}
static T* alloc()
{
// return new T;
Slab<T> *instance=getInstance();
if(!instance->dataList.empty())
{
list<void*>::iterator it=instance->dataList.begin();
T *p=(T*)*it;
instance->dataList.pop_front();
return p;
}
else
{
T* p=new T;
return (T*)p;
}
}
static void dealloc(void *p)
{
// delete((T*) p);
((T*)p)->reuse();
Slab<T> *instance=getInstance();
instance->dataList.push_back(p);
}
private:
list<void *> dataList;
// static Slab<T> *instance;
};
#endif