MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Add

Method Add

Source/Engine/Core/Collections/ChunkedArray.h:243–268  ·  view source on GitHub ↗

Adds the specified item to the collection. The item. The pointer to the allocated item in the storage.

Source from the content-addressed store, hash-verified

241 /// <param name="item">The item.</param>
242 /// <returns>The pointer to the allocated item in the storage.</returns>
243 T* Add(const T& item)
244 {
245 // Find first chunk with some space
246 Chunk* chunk = nullptr;
247 for (int32 i = 0; i < _chunks.Count(); i++)
248 {
249 if (_chunks[i]->Count() < ChunkSize)
250 {
251 chunk = _chunks[i];
252 break;
253 }
254 }
255
256 // Allocate chunk if missing
257 if (chunk == nullptr)
258 {
259 chunk = New<Chunk>();
260 chunk->SetCapacity(ChunkSize);
261 _chunks.Add(chunk);
262 }
263
264 // Add item
265 _count++;
266 chunk->Add(item);
267 return &chunk->At(chunk->Count() - 1);
268 }
269
270 /// <summary>
271 /// Adds the one item to the collection and returns the reference to it.

Callers 2

ChunkedArrayClass · 0.45
EnsureCapacityMethod · 0.45

Calls 2

CountMethod · 0.45
SetCapacityMethod · 0.45

Tested by

no test coverage detected