Do you use D's GC?
Steven Schveighoffer
schveiguy at gmail.com
Tue Aug 3 19:22:08 UTC 2021
On 8/3/21 3:16 PM, jfondren wrote:
> 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.
Yep, correct! Sorry I didn't see this before I did the other reply.
-Steve
More information about the Digitalmars-d
mailing list