gamut icon indicating copy to clipboard operation
gamut copied to clipboard

Reuseing allocation when?

Open p0nce opened this issue 1 year ago • 1 comments

  • [ ] try to reuse former allocation when chaining create functions, often the former allocation is forgotten for no reason... But reusing the allocation is perhaps a prime reason to reuse the Image?

  • [ ] allocating storage should return a slice, and take a slice for former allocation

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 avatar Jan 08 '23 23:01 p0nce