[Issue 4487] New: 16 bytes long structs requires 32 bytes if allocated singularly on the heap

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 19 12:47:17 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4487

           Summary: 16 bytes long structs requires 32 bytes if allocated
                    singularly on the heap
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: performance
          Severity: major
          Priority: P2
         Component: druntime
        AssignedTo: sean at invisibleduck.org
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-07-19 12:46:34 PDT ---
(This is my first bug report with 'major' severity, because this is a quite
important bug.)

This comes after a report by Steven Schveighoffer. This program allocates a
linked list of 10 million structs on the heap (this number is set to high just
to improve the measurements).

The presence of GC.disable() doesn't change the total memory allocated, but
decreases a lot the run time. On a 32 bit Windows at the end of the list
allocation this program has allocated about 326 MB, it means:

326_200_000 bytes / 10_000_000 ~= 32.62 bytes each Foo

This can't be accepted in a serious "system language" (also because 16 bytes
long structs are quite common in my 32 bit code).

import core.memory: GC;
struct Foo {
    Foo* next;
    ubyte[12] arr;
    this(Foo* ptr) { this.next = ptr; }
}
static assert(Foo.sizeof == 16);
void main() {
    GC.disable();
    enum n = 10_000_000;
    Foo* lh;
    foreach (i; 0 .. n)
        lh = new Foo(lh);
    GC.enable();
}


Maybe this bug can be fixed introducing a specific allocator function for
single structs, that don't sees them as arrays of length 1 (that needs 1 byte
of information padding for appends).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list