#ifndef LINK_H
#define LINK_H
template<typename E>
class Link
{
private:
static Link<E>* freelist;
public:
E element;
Link<E>* next;
Link(const E& elemval, Link<E>* nextval = NULL)
{
element = elemval;
next = nextval;
}
Link(Link<E>* nextval = NULL)
{
next = nextval;
}
void* operator new (size_t)
{
if(freelist == NULL) return ::new Link;
Link<E>* temp = freelist;
freelist = freelist->next;
return temp;
}
void operator delete(void* ptr)
{
((Link<E>*) ptr)->next = freelist;
freelist = (Link<E>*)ptr;
}
};
template<typename E>
Link<E>* Link<E>::freelist = NULL;
#endif
- May 02 Fri 2014 17:34
運用 freelist 機制提昇串列節點記憶體配發效率的方法
close
全站熱搜
留言列表