On Wed, 25 Apr 2007, Michael Marcin wrote: [...]
I originally wrote that using a scoped_array to document the lifetime, ownership, and type of data pointed to. And so I didn't have to worry about things like forgetting to call delete[] instead of delete. I figured that any compiler worth using should inline this out to the same code as the "optimized" version but I have no proof of that I was hoping someone would have done simple tests comparing generated code that I could reference when I discuss these "improvements" with the team later this week. [...]
I did a simple test (code below). By changing delete to delete[] and
compiling as (using gcc-4.0.3)
g++ -o test_n test.cpp -O3
and
g++ -o test_b test.cpp -O3
and then disassembling the two binaries (objdump -d ...) and comparing the
generated code, I could see that the generated code for the 'test'
function was identical in both case. The code is of course a little bit
different between delete and delete[].
#include <iostream>
#ifdef USE_BOOST
#include