Пример #1
0
inline void* MemoryManager::smartMalloc(size_t nbytes) {
  auto const nbytes_padded = nbytes + sizeof(SmallNode);
  if (LIKELY(nbytes_padded) <= kMaxSmartSize) {
    auto const ptr = static_cast<SmallNode*>(smartMallocSize(nbytes_padded));
    ptr->padbytes = nbytes_padded;
    ptr->kind = HeaderKind::SmallMalloc;
    return ptr + 1;
  }
  return smartMallocBig(nbytes);
}
Пример #2
0
inline void* MemoryManager::smartMalloc(size_t nbytes) {
  nbytes += sizeof(SmallNode);
  if (UNLIKELY(nbytes > kMaxSmartSize)) {
    return smartMallocBig(nbytes);
  }

  auto const ptr = static_cast<SmallNode*>(smartMallocSize(nbytes));
  ptr->padbytes = nbytes;
  return ptr + 1;
}
Пример #3
0
inline void* MemoryManager::smartMalloc(size_t nbytes) {
  nbytes += sizeof(SmallNode);
  if (UNLIKELY(nbytes > kMaxSmartSize)) {
    return smartMallocBig(nbytes);
  }

  nbytes = smartSizeClass(nbytes);
  m_stats.usage += nbytes;

  auto const idx = (nbytes - 1) >> kLgSizeQuantum;
  assert(idx < kNumSizes && idx >= 0);
  void* vp = m_sizeTrackedFree[idx].maybePop();
  if (UNLIKELY(vp == nullptr)) {
    return smartMallocSlab(nbytes);
  }
  FTRACE(1, "smartMalloc: {} -> {}\n", nbytes, vp);

  return vp;
}