C 記憶體池的實現

2021-06-02 00:30:11 字數 1168 閱讀 9803

/*  @file       memorypool.h

*   @note       hangzhou hikvision system technology co., ltd. all right reserved.

*   @brief      windows下記憶體池的實現

*   @author    

[email protected]

*   @date       11/15/2011

*   @note       v1.0  created.

*/ #pragma once

#ifndef _memory_pool_

#define _memory_pool_

#include

#include

using std::list;

template

class memorypool

;template

memorypool::memorypool(int nmax)

m_nmaxcount=nmax;

m_nfreecount=m_nmaxcount;

}else

initializecriticalsection(&m_csmemlock);

}template

inline memorypool ::~memorypool()

template

type* memorypool ::new()

return pnew;

}template

void memorypool ::delete(type* p)

}list::iterator iter;

for (iter = m_pmemlist.begin();iter != m_pmemlist.end();++iter)

}if (p != null && m_ptype != null && m_nfreecount < m_nmaxcount && bisvalaidpointer)

}template

inline int memorypool::getfreecount() //獲取剩餘容量

template

inline bool memorypool ::isfull()

#endif

記憶體池的C 實現。

原文 最近在學習c 程式效能優化,讀到記憶體池部分。自己動手寫了乙個,小小測試了一下應該沒有問題。記憶體塊memoryblock宣告檔案 cpp view plain copy pragma once define ushort unsigned short define ulong unsigne...

C 記憶體池的實現

記憶體池是一種自主的記憶體管理機制。就是將我們的記憶體管理放在了應用程式端。那麼它的簡單處理做了什麼事呢?首先,我們從堆上分配出一塊很大的記憶體塊。接著我們按照劃分將其劃分成每個不同的小組。這個每個小組儲存乙個資料塊。針對於每個小組的組內來說就是乙個簡單的資料結構。這個資料結構我們將其分為兩個部分,...

記憶體池 C 記憶體池

c c 下記憶體管理是讓幾乎每乙個程式設計師頭疼的問題,分配足夠的記憶體 追蹤記憶體的分配 在不需要的時候釋放記憶體 這個任務相當複雜。1.呼叫malloc new,系統需要根據 最先匹配 最優匹配 或其他演算法在記憶體空閒塊表中查詢一塊空閒記憶體,呼叫free delete,系統可能需要合併空閒記...