⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 topslotheap.h

📁 hoard内存管理器
💻 H
字号:
/* -*- C++ -*- */#ifndef _TOPSLOTHEAP_H_#define _TOPSLOTHEAP_H_#include <assert.h>#include "bigchunk.h"/*  TopSlotHeap.  malloc returns objects of size chunkSize.  free returns objects of size chunkSize.*/template <int chunkSize, int slotSize, class Super>class TopSlotHeap : public Super {public:  TopSlotHeap (void)    : myChunks (NULL)  {}  // Get a chunkSize object.  inline void * malloc (size_t sz);  // Free a chunkSize object.  inline void free (void * ptr);protected:	virtual inline void localFree (void * ptr);	private:  BigChunk<chunkSize, slotSize, TopSlotHeap> * myChunks;};template <int chunkSize, int slotSize, class Super>void * TopSlotHeap<chunkSize, slotSize, Super>::malloc (size_t sz){  assert (sz <= chunkSize);  if (myChunks == NULL) {	return new (Super::malloc (chunkSize)) BigChunk<chunkSize, slotSize, TopSlotHeap>;  } else {	printf ("Recycled a chunk.\n");	BigChunk<chunkSize, slotSize, TopSlotHeap> * ch = myChunks;	myChunks = myChunks->getNext();	ch->setNext (NULL);	ch->setHeap (NULL);	return ch;  }}template <int chunkSize, int slotSize, class Super>void TopSlotHeap<chunkSize, slotSize, Super>::free (void * ptr) {  printf ("Freed a chunk.\n");  BigChunk<chunkSize, slotSize, TopSlotHeap> * ch = (BigChunk<chunkSize, slotSize, TopSlotHeap> *) ptr;  ch->setNext (myChunks);  ch->setHeap (this);  myChunks = ch;}template <int chunkSize, int slotSize, class Super>void TopSlotHeap<chunkSize, slotSize, Super>::localFree (void * ptr) {	free (ptr);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -