MCPcopy Create free account
hub / github.com/beefytech/Beef / TCMalloc_SystemAlloc

Function TCMalloc_SystemAlloc

BeefTools/BeefMem/gperftools/src/system-alloc.cc:482–513  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

480}
481
482void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size,
483 size_t alignment) {
484 // Discard requests that overflow
485 if (size + alignment < size) return NULL;
486
487 SpinLockHolder lock_holder(&spinlock);
488
489 if (!system_alloc_inited) {
490 InitSystemAllocators();
491 system_alloc_inited = true;
492 }
493
494 // Enforce minimum alignment
495 if (alignment < sizeof(MemoryAligner)) alignment = sizeof(MemoryAligner);
496
497 void* result = sys_alloc->Alloc(size, actual_size, alignment);
498 if (result != NULL) {
499 if (actual_size) {
500 CheckAddressBits<kAddressBits>(
501 reinterpret_cast<uintptr_t>(result) + *actual_size - 1);
502 TCMalloc_SystemTaken += *actual_size;
503 } else {
504 CheckAddressBits<kAddressBits>(
505 reinterpret_cast<uintptr_t>(result) + size - 1);
506 TCMalloc_SystemTaken += size;
507 }
508 }
509
510 //printf("Allocated from %08X to %08X\n", result, (void*)((char*)result + (int)*actual_size));
511
512 return result;
513}
514
515bool TCMalloc_CanRelease()
516{

Callers 2

GrowHeapMethod · 0.70
MetaDataAllocFunction · 0.70

Calls 2

InitSystemAllocatorsFunction · 0.70
AllocMethod · 0.45

Tested by

no test coverage detected