wavelength 1.0.0
Loading...
Searching...
No Matches
memhandle.h
Go to the documentation of this file.
1#pragma once
2
3#include <stddef.h>
4
5#include "os/mem.h"
6
7class MemHandle;
8
13 int mReserved[2]; // +0x08, padding that puts the data on a 16-byte boundary.
14};
15
21class MemHandle {
22public:
30 explicit MemHandle(HandleBlock *pBlock);
31
37 static void *operator new(size_t) {
38 return PoolAlloc(sizeof(MemHandle), sizeof(MemHandle), "MemHandle", 0);
39 }
40
46 static void operator delete(void *pBlock) {
47 PoolFree(sizeof(MemHandle), pBlock);
48 }
49
61 static MemHandle *Alloc(int nBytes, const char *pszTag);
62
72 static void Free(MemHandle *pHandle);
73
81 void *Lock();
82
89 void Unlock();
90
99 void *Resize(int nBytes);
100
103 return mBlock;
104 }
105
107 void SetBlock(HandleBlock *pBlock) {
108 mBlock = pBlock;
109 }
110
111private:
112 HandleBlock *mBlock;
113};
Movable block of a handle heap, reached through a handle the block points back to.
Definition memhandle.h:21
MemHandle(HandleBlock *pBlock)
Attach the handle to a block with no locks.
void * Resize(int nBytes)
Shrink the block in place through MemRealloc().
void * Lock()
Count a lock and report the data.
HandleBlock * GetBlock() const
Definition memhandle.h:102
void SetBlock(HandleBlock *pBlock)
Definition memhandle.h:107
static MemHandle * Alloc(int nBytes, const char *pszTag)
Allocate a block and a handle for it.
static void Free(MemHandle *pHandle)
Free a handle and its block.
void Unlock()
Undo one Lock().
void * PoolAlloc(int nSize, int nBlockSize, const char *pszTag, int nUnused)
Allocate a block from the small-block pool and bill it to a tag.
void PoolFree(int nSize, void *pBlock)
Return a block to the small-block pool.
The 16-byte header of a block a MemHandle refers to.
Definition memhandle.h:10
int mLockCount
Definition memhandle.h:12
MemHandle * mHandle
Definition memhandle.h:11
int mReserved[2]
Definition memhandle.h:13