MCPcopy Create free account
hub / github.com/JACoders/OpenJK / Alloc

Method Alloc

code/qcommon/hstring.cpp:108–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108void *CMapPoolLow::Alloc()
109{
110 // Try to request a node. First we look in the free-list, but if that
111 // happens to be empty, we allocate more storage in the current CMapBlock.
112 void *node=0;
113 if(mFreeList.size())
114 {
115 // Retrieve the node to be recycled.
116 node=(void *)mFreeList[mFreeList.size()-1];
117 mFreeList.pop_back();
118 }
119 else
120 {
121 // None free, so alloc another block.
122 CMapBlock *block=new CMapBlock(mLastBlockNum+1,mFreeList);
123 assert(block);
124 mMapBlocks.push_back(block);
125 mLastBlockNum++;
126 node=(void *)mFreeList[mFreeList.size()-1];
127 mFreeList.pop_back();
128 }
129
130 // Validate we aren't somehow grabbing something that is already in use
131 // and also that the end marker is intact.
132 assert(((SMapNode *)node)->mTag==MAPNODE_FREE);
133 assert((((SMapNode *)node)->mMapBlockNum)>=0);
134 assert((((SMapNode *)node)->mMapBlockNum)<256);
135 assert((((SMapNode *)node)->mMapBlockNum)<=mLastBlockNum);
136 assert(mMapBlocks[((SMapNode *)node)->mMapBlockNum]->bOwnsNode(node));
137
138 // Ok, mark the node as in use.
139 ((SMapNode *)node)->mTag=MAPNODE_INUSE;
140
141 return(node);
142}
143
144void CMapPoolLow::Free(void *p)
145{

Callers 4

AllocMethod · 0.45
InitMethod · 0.45
allocateMethod · 0.45
_CharallocMethod · 0.45

Calls 4

bOwnsNodeMethod · 0.80
sizeMethod · 0.45
pop_backMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected