News for hackers. Stuff that matters.
Re:Benchmarking C++ Allocators by jeffbee on Monday April 27, 2020 @03:52PM (#22999299)
There are a wide variety of outcomes available when the implementation of global operator new is visible to the compiler. It may inline the entire new, and having done so it may also apply any other optimization that would apply to any other function. Without an allocator at build time the only thing it can do it generate a call to malloc. Leaving malloc resolution to runtime also negates all benefits of sized delete.
Re:Benchmarking C++ Allocators by saagarjha on Monday April 27, 2020 @04:30PM (#22999683)
Have you ever seen operator new inlined in pratice? I've always seen it make a call to malloc, because I can't think of a compiler actually containing the implementation of a memory allocator inside of it…
Re:Benchmarking C++ Allocators by mehrdadn on Monday April 27, 2020 @04:53PM (#22999915)
I'm completely aware of everything you said, but it's not what I asked. I was very specifically not asking what is theoretically possible but what actually happens in practice. Because I don't see any evidence that this is actually the case in practice. For a memory allocator that has a legitimate general-purpose deallocator (i.e. ones that are reasonable replacements for malloc/free), my experience says this kind of overhead being worth optimizing is very much hypothetical rather than the reality. Of course for allocators that skip half the steps (e.g. don't bother to return memory dynamically or only work in specific cases) then the story might be very different but it's not really fair to compare them against general purpose ones?

Now I'm perfectly happy to accept my imagination/experience is just lacking and that's why I don't see such use cases, but I'm seeing multiple other top comments voicing the same concerns as I am, so I'm mostly suggesting a plausible example to demonstrate this is likely to really help convince people this might be the right thing to focus on.

Re:Benchmarking C++ Allocators by the8472 on Monday April 27, 2020 @04:22PM (#22999592)
My understanding is that compilers are allowed to treat malloc specially, i.e. they can assume that it returns non-aliasing memory, does not mutate other memory and can be elided if its result is unused.
Re:Benchmarking C++ Allocators by mehrdadn on Monday April 27, 2020 @05:29PM (#23000292)
I'm not aware of that being a blanket assumption they can make, is it? (Is it in the C++ standard?) That kind of thing is generally dictated by compiler-specific annotations (noalias etc.) which you can put on any function, and which shouldn't apply unless you write them explicitly...
Re:Benchmarking C++ Allocators by gpderetta on Monday April 27, 2020 @08:34PM (#23001979)
on gcc you can use __attribute__((malloc)) to tell the compiler that your function is malloc-like (i.e. its result type won't alias any other pointer), but any call to the litterall 'malloc' function itself is implicitly treated as such even if you do not include the appropriate header and declare it yourself (you can use -fno-builtin-functions or -free-standing or something like that to disable this treatment).
Re:Benchmarking C++ Allocators by jcranmer on Tuesday April 28, 2020 @01:03AM (#23003567)
LLVM is capable of eliminating calls to malloc if it can prove that they don't escape the function.
Re:Benchmarking C++ Allocators by saagarjha on Tuesday April 28, 2020 @03:24AM (#23004416)
Even if the allocation is large?