コード例 #1
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;
}
コード例 #2
0
inline void* MemoryManager::smartMalloc(size_t nbytes) {
  ASSERT(nbytes > 0);
  // add room for header before rounding up
  size_t padbytes = (nbytes + sizeof(SmallNode) + kMask) & ~kMask;
  if (LIKELY(padbytes <= kMaxSmartSize)) {
    m_stats.usage += padbytes;
    unsigned i = (padbytes - 1) >> kLgSizeQuantum;
    ASSERT(i < kNumSizes);
    void* p = m_smartfree[i].maybePop();
    if (LIKELY(p != 0)) return p;
    char* mem = m_front;
    if (LIKELY(mem + padbytes <= m_limit)) {
      m_front = mem + padbytes;
      SmallNode* n = (SmallNode*) mem;
      n->padbytes = padbytes;
      return n + 1;
    }
    return smartMallocSlab(padbytes);
  }