Do you use D's GC?
jfondren
julian.fondren at gmail.com
Tue Aug 3 19:16:23 UTC 2021
On Tuesday, 3 August 2021 at 19:04:06 UTC, jfondren wrote:
> ```d
> void ensureHasRoom(ref ubyte[] buffer, size_t length) {
> buffer.length = length; // this is a serious bottleneck
> }
>
> void ensureHasRoom(ref ubyte[] buffer, size_t length) {
> if (buffer.length < length) {
> buffer.length = length; // this is fine actually
> }
> }
> ```
>
> The story is that the situation was improved by excluding only
> those cases that should not have incurred any reallocations.
> Every single invocation of the bottlenecking `ensureHasRoom`
> that should have reallocated would still do so with the fixed
> `ensureHasRoom`. So something else was going on.
ah. No, I get it: this was probably shrinking and then regrowing
buffer.length across separate calls, which would incur
reallocations on the regrowth.
More information about the Digitalmars-d
mailing list