MCPcopy Create free account
hub / github.com/defold/defold / Free

Method Free

engine/dlib/src/dmsdk/dlib/object_pool.h:158–181  ·  view source on GitHub ↗

* Returns object index to the object pool * * @name Free * @param index [type: uint32_t] index of object * @param clear [type: bool] If set, memset's the object memory */

Source from the content-addressed store, hash-verified

156 * @param clear [type: bool] If set, memset's the object memory
157 */
158 void Free(uint32_t index, bool clear)
159 {
160 uint32_t size = m_Objects.Size();
161 Entry* e = &m_Entries[index];
162 uint32_t last = m_ToLogical[size - 1];
163 assert(e->m_Physical < size);
164
165 T* o = &m_Objects[e->m_Physical];
166 if (clear) {
167 memset(o, 0, sizeof(T));
168 }
169
170 // Remap logical/physical
171 m_Entries[last].m_Physical = e->m_Physical;
172 m_ToLogical[e->m_Physical] = last;
173
174 // Remove
175 m_Objects.EraseSwap(e->m_Physical);
176
177 // Put in free list
178 e->m_Next = m_FirstFree;
179 e->m_Physical = 0xffffffff;
180 m_FirstFree = e - m_Entries.Begin();
181 }
182
183 /*#
184 * Get the array of currently active objects

Callers 1

FreeJobFunction · 0.45

Calls 3

assertFunction · 0.50
SizeMethod · 0.45
BeginMethod · 0.45

Tested by

no test coverage detected