SpiecsEngine
 
Loading...
Searching...
No Matches

◆ Allocate()

void * Spices::ThreadCache::Allocate ( size_t size)

Allocate memory.

Parameters
[in]sizememory bytes.
Returns
Returns memory pointer.

Only allowed allocate 258KB one tme.

Determain aligned size and freelist index.

Fetch memory from freelist.

Fetch memory from cc;

Only allowed allocate 258KB one tme.

Determain aligned size and freelist index.

Fetch memory from freelist.

Fetch memory from cc;

Definition at line 28 of file ThrealCache.cpp.

29 {
33 assert(size <= MemoryPool::MAX_BYTES);
34
38 const size_t alignSize = MemoryPool::AlignUp(size);
39 const size_t index = MemoryPool::Index(size);
40
44 if (!m_FreeLists[index].Empty())
45 {
46 return m_FreeLists[index].Pop();
47 }
48
52 else
53 {
54 return FetchFromCentralCache(index, alignSize);
55 }
56 }
static constexpr size_t MAX_BYTES
Only allowed 256KB allocated memory one time in tc.
Definition MemoryPool.h:34
static size_t Index(size_t size)
Determine which freelist should process the memory block with given bytes.
static size_t AlignUp(size_t size)
Align up memory bytes.
void * FetchFromCentralCache(size_t index, size_t alignSize)
Fetch memory from central cache if this is run out.
std::array< scl::free_list, MemoryPool::FREE_LIST_NUM > m_FreeLists
FreeList Array.
Definition ThrealCache.h:81