wavelength 1.0.0
Loading...
Searching...
No Matches
freestore.h
Go to the documentation of this file.
1#pragma once
2
3#include <stddef.h>
4
5#include "os/mem.h"
6#include "script/dataarray.h"
7
14class FreeStore {
15public:
17 struct Node {
19 };
20
28 explicit FreeStore(int nNodeWords);
29
36 static void *operator new(size_t nSize) {
37 return PoolMemAlloc(static_cast<int>(nSize), "FixedSizeAlloc", 0);
38 }
39
47 void *Alloc();
48
56 void Free(void *pNode);
57
64 void Grow();
65
74 void *AllocChunk(int nBytes);
75
87 void
88 GetStats(int *pnNodeBytes, int *pnAllocs, int *pnMaxAllocs, int *pnCapacity, int *pnWasted);
89
99 static void Configure(DataArray *pConfig);
100
109 static void *AllocHunk(int nBytes);
110
117 static int sHunkBytes;
118
119private:
120 int mNodeWords;
121 int mNumAllocs;
122 int mMaxAllocs;
123 int mNumChunks;
124 Node *mFree;
125 int mNodesPerChunk;
126};
Reference-counted array of script data nodes.
Definition dataarray.h:20
static int sHunkBytes
The bytes AllocHunk() has handed out.
Definition freestore.h:117
void * AllocChunk(int nBytes)
Take a chunk of nodes from the hunks of the pool.
void GetStats(int *pnNodeBytes, int *pnAllocs, int *pnMaxAllocs, int *pnCapacity, int *pnWasted)
Report the use of the store.
void * Alloc()
Hand out a node, growing the store when none is free.
void Free(void *pNode)
Return a node.
FreeStore(int nNodeWords)
Construct an empty store.
void Grow()
Add a chunk of mNodesPerChunk free nodes.
static void Configure(DataArray *pConfig)
Read the sizes of the pool's hunks from the pool block of the mem configuration.
static void * AllocHunk(int nBytes)
Carve bytes from the current hunk of the pool, allocating a new hunk when they do not fit.
void * PoolMemAlloc(int nSize, const char *pszTag, int nAlign)
Allocate a block from the pool heaps and bill it to a tag.
A free node, which starts with the link to the next one.
Definition freestore.h:17
Node * mNext
Definition freestore.h:18