2

I compared 2 different malloc versions and asked about malloc and free where a test first resulted in that one malloc was faster than the other and then a comment or answer was that if you allocate or free in a random order or similar change then the basic malloc was not faster than the regular malloc if you deallocate in reverse order.

I wrote a loop that disproved a test result because of the answer. The commit is online and available but I have forgotten why I added the test to deallocate in reverse order. I don't remember why I would do it. There was a comment or answer that made me do it and that disproved earlier tests that a basic malloc would be faster than the builtin malloc, according to expectation.

The background was that tests showed that a custom malloc was faster than the builtin malloc but that seemed unlikely. When deallocating in reverse order the builtin malloc was faster. But why would I deallocate in reverse order? I already asked about it but I can't find the question I asked.

Can you help me find the question so that I can understand why the test with reverse order deallocation disproved the earlier tests?

1
  • 1
    code shown in diff as removed looks like a very weak test: one can argue that smart enough compiler could optimise malloc immediately followed by free to do nothing at all. Similarly, if you just split it to two identical loops first doing malloc and second doing free, there is a risk that compiler recognises this, joins the loops and gets you back to the very issue you were trying to avoid, too easy to optimise malloc immediately followed by free. Second loop doing free in reverse order is less likely to be optimised like that (still not very convincing to my taste but better)
    – gnat
    Jan 21, 2017 at 7:30

0

You must log in to answer this question.

Browse other questions tagged .