Bug 20566 – std.sformat should avoid allocating memory when printing floating point values
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2020-02-08T07:32:00Z
Last change time
2020-02-12T08:21:27Z
Keywords
pull
Assigned to
No Owner
Creator
Rainer Schuetze
Comments
Comment #0 by r.sagitario — 2020-02-08T07:32:00Z
from https://digitalmars.com/d/archives/digitalmars/D/learn/format_with_floating_points_GC_allocating_in_DMD_2.090_113888.html :
import std.format;
import core.memory;
import std.stdio;
import std.format;
void main()
{
char[4096] buf;
writeln(GC.stats.usedSize);
foreach (i; 0 .. 10) {
sformat(buf[], "%a", 1.234f);
writeln(GC.stats.usedSize);
}
}
shows that an invocation of sformat allocates, even though a large buffer is passed in. This didn't happen in 2.089, but in 2.090 and all other versions before 2.089.
Comment #1 by dlang-bot — 2020-02-08T07:43:12Z
@rainers created dlang/phobos pull request #7393 "fix Issue 20566 - std.sformat should avoid allocating memory when pri…" fixing this issue:
- fix Issue 20566 - std.sformat should avoid allocating memory when printing floating point values
use stack allocated buffers as long as the required precision is within reasonable values
https://github.com/dlang/phobos/pull/7393
Comment #2 by dlang-bot — 2020-02-12T08:21:27Z
dlang/phobos pull request #7393 "fix Issue 20566 - std.sformat should avoid allocating memory when pri…" was merged into master:
- b22070d5d6e4f329b632570f2e03432d913dc522 by Rainer Schuetze:
fix Issue 20566 - std.sformat should avoid allocating memory when printing floating point values
use stack allocated buffers as long as the required precision is within reasonable values
https://github.com/dlang/phobos/pull/7393