Why is ::operator new[] necessary when ::operator new is enough?

后端 未结 5 999
谎友^
谎友^ 2020-12-24 13:18

As we know, the C++ standard defines two forms of global allocation functions:

void* operator new(size_t);
void* operator new[](size_t);

An

5条回答
  •  梦谈多话
    2020-12-24 13:48

    ::operator new[] and ~delete[] facilitate memory usage debugging, being a central point to audit allocation and deallocation operations; you can then ensure the array form is used for both or neither.

    There are also lots of plausible if highly unusual/crude tuning uses:

    • allocate arrays from a separate pool, perhaps because that crucially improved average cache hits for small single-object dynamically-allocated objects,

    • different memory access hints (ala madvise) for array/non-array data

    All that's a bit weird and outside the day-to-day concerns of 99.999% of programmers, but why prevent it being possible?

提交回复
热议问题