www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20566] New: std.sformat should avoid allocating memory when

https://issues.dlang.org/show_bug.cgi?id=20566

          Issue ID: 20566
           Summary: std.sformat should avoid allocating memory when
                    printing floating point values
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: r.sagitario gmx.de

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.

--
Feb 07