AuburnSounds / gamut

Image encoding and decoding library for D. Detailed layout control. Experimental codec QOIX.
Boost Software License 1.0
41 stars 2 forks source link

Reuseing allocation when? #40

Open p0nce opened 1 year ago

p0nce commented 1 year ago

Is realloc worth it vs free+malloc? Sometimes yes.

 // PERF: on Windows, reusing previous allocation is much faster for same alloc size
    //       314x faster             vs free+malloc for same size
    //       10x faster              vs free+malloc for decreasing size 1 by 1
    //       424x slower (quadratic) vs free+malloc for increasing size 1 by 1
    //       0.5x slower             vs free+malloc for random size

If we store the allocation as slice, we could second guess realloc().

p0nce commented 1 year ago