blob: 860e9df7efe84c3af9eaa97f2b20f7e5f77e6945 (
plain) (
blame)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// The copyright to the contents herein is the property of Valve, L.L.C.
// The contents may be used and/or copied only with the written permission of
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
// the agreement/contract under which the contents have been supplied.
//
// Purpose:
//
// $Workfile: $
// $Date: $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================
#ifndef TSMULTIMEMPOOL_H
#define TSMULTIMEMPOOL_H
#ifdef _WIN32
#pragma once
#endif
#include "tier1/utlmap.h"
#include "tier1/mempool.h"
#include "tier1/tsmempool.h"
//-----------------------------------------------------------------------------
// Purpose: A container of a range of mem pool sizes (for network buffers for example)
// and a raw alloc capability (for sizes greater than any contained mem pool).
//-----------------------------------------------------------------------------
class CThreadSafeMultiMemoryPool
{
public:
struct MemPoolConfig_t
{
uint32 m_cubBlockSize;
uint32 m_cubDefaultPoolSize;
};
CThreadSafeMultiMemoryPool( const MemPoolConfig_t *pnBlock, int cnMemPoolConfig, int nGrowMode = UTLMEMORYPOOL_GROW_FAST );
~CThreadSafeMultiMemoryPool();
// Allocate a block of at least nAllocSize bytes
void* Alloc( uint32 cubAlloc );
// Free a previously alloc'd block
void Free(void *pvMem);
// ReAllocate a previously allocated block to a new size
void* ReAlloc( void *pvMem, uint32 cubAlloc );
// Frees everything
void Clear();
// alloc size for this bit of alloc'd memory
int CubAllocSize( void *pvMem );
// prints details about our contained memory
void PrintStats();
// total number of alloc'd elements
int Count();
// Return the total size in MB allocated for this pool
int CMBPoolSize() const;
// Return the amount of memory in use
int CMBPoolSizeInUse() const;
#ifdef DBGFLAG_VALIDATE
void Validate( CValidator &validator, const char *pchName ); // Validate our internal structures
#endif // DBGFLAG_VALIDATE
private:
struct MemPoolRecord_t
{
CThreadSafeMemoryPool *m_pMemPool;
uint32 m_nBlockSize;
};
CUtlVector<MemPoolRecord_t> m_VecMemPool; // stores our list of mem pools
uint32 m_nBlockSizeMax;
CUtlVector<MemPoolRecord_t *> m_VecMemPoolLookup; // quick lookup table of mempools
struct RawAllocation_t
{
void *m_pvMem;
uint32 m_nBlockSize;
};
CUtlMap<void *,RawAllocation_t,int> m_MapRawAllocation; // stores our list of raw alloc'd mem
CThreadFastMutex m_mutexRawAllocations;
uint32 m_cubReallocedTotal;
};
#endif // TSMULTIMEMPOOL_H
|