/////////////////////////////////////////////////////////////////////
| 1510 | |
| 1511 | ////////////////////////////////////////////////////////////////////////// |
| 1512 | static Y_FORCE_INLINE void* LFAllocImpl(size_t _nSize) { |
| 1513 | #if defined(LFALLOC_DBG) |
| 1514 | size_t size = _nSize; |
| 1515 | _nSize += sizeof(TAllocHeader); |
| 1516 | #endif |
| 1517 | |
| 1518 | IncrementCounter(CT_USER_ALLOC, _nSize); |
| 1519 | |
| 1520 | int nSizeIdx; |
| 1521 | if (_nSize > 512) { |
| 1522 | if (_nSize > N_MAX_FAST_SIZE) { |
| 1523 | void* ptr = LargeBlockAlloc(_nSize, CT_LARGE_ALLOC); |
| 1524 | #if defined(LFALLOC_DBG) |
| 1525 | ptr = TrackAllocation(ptr, size, N_SIZES); |
| 1526 | #endif |
| 1527 | return ptr; |
| 1528 | } |
| 1529 | nSizeIdx = size2idxArr2[(_nSize - 1) >> 8]; |
| 1530 | } else |
| 1531 | nSizeIdx = size2idxArr1[1 + (((int)_nSize - 1) >> 3)]; |
| 1532 | |
| 1533 | IncrementCounter(CT_SMALL_ALLOC, nSizeIdxToSize[nSizeIdx]); |
| 1534 | |
| 1535 | // check per thread buffer |
| 1536 | TThreadAllocInfo* thr = pThreadInfo; |
| 1537 | if (!thr) { |
| 1538 | AllocThreadInfo(); |
| 1539 | thr = pThreadInfo; |
| 1540 | if (!thr) { |
| 1541 | void* ptr = LFAllocNoCache(nSizeIdx, MEM_DEFRAG); |
| 1542 | #if defined(LFALLOC_DBG) |
| 1543 | ptr = TrackAllocation(ptr, size, nSizeIdx); |
| 1544 | #endif |
| 1545 | return ptr; |
| 1546 | } |
| 1547 | } |
| 1548 | { |
| 1549 | int& freePtrIdx = thr->FreePtrIndex[nSizeIdx]; |
| 1550 | if (freePtrIdx < THREAD_BUF) { |
| 1551 | void* ptr = thr->FreePtrs[nSizeIdx][freePtrIdx++]; |
| 1552 | #if defined(LFALLOC_DBG) |
| 1553 | ptr = TrackAllocation(ptr, size, nSizeIdx); |
| 1554 | #endif |
| 1555 | return ptr; |
| 1556 | } |
| 1557 | |
| 1558 | // try to alloc from global free list |
| 1559 | char* buf[FL_GROUP_SIZE]; |
| 1560 | int count = TakeBlocksFromGlobalFreeList(nSizeIdx, buf); |
| 1561 | if (count == 0) { |
| 1562 | count = LFAllocNoCacheMultiple(nSizeIdx, buf); |
| 1563 | if (count == 0) { |
| 1564 | NMalloc::AbortFromCorruptedAllocator("no way LFAllocNoCacheMultiple() can fail"); |
| 1565 | } |
| 1566 | } |
| 1567 | char** dstBuf = thr->FreePtrs[nSizeIdx] + freePtrIdx - 1; |
| 1568 | for (int i = 0; i < count - 1; ++i) |
| 1569 | dstBuf[-i] = buf[i]; |
no test coverage detected