www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8820] New: Array initialization generates garbage

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8820

           Summary: Array initialization generates garbage
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody puremagic.com
        ReportedBy: malteskarupke web.de



PDT ---
Array initialization currently generates garbage that needs to be collected by
the GC.

{
    int[5] a = [1, 2, 3, 4, 5]; // generates garbage
}
{
    int[5] a;
    foreach (i; 0 .. 5)
    {
        a[i] = i + 1;
    } // same thing, but no garbage. everything is on the stack
}


Creating an array on the stack should be a trivial and fast operation. Yet
stepping through the disassembly of that first line reveals a lot of overhead.

But for now all I want fixed is that the first line does not generate garbage.
The reason for why it generates garbage is that it allocates on the heap, then
memcpys over to the stack, and never cleans up the memory on the heap.

It should obviously initialize directly on the stack.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 14 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8820


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jmdavisProg gmx.com
         Resolution|                            |DUPLICATE



PDT ---
*** This issue has been marked as a duplicate of issue 2356 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 14 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8820




PDT ---
This is a long-standing, known issue.

As a side note, it would be better to say that it allocates memory when it
shouldn't rather than talking about generating garbage. That tends to imply
that it generates garbage data (which it doesn't), giving the wrong impression
about what you're talking about. All GC heap memory must naturally be garbage
collected, so the issue is that it's allocated in the first place rather than
the fact that it needs to be collected later.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 14 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8820




PDT ---

 This is a long-standing, known issue.
 
 As a side note, it would be better to say that it allocates memory when it
 shouldn't rather than talking about generating garbage. That tends to imply
 that it generates garbage data (which it doesn't), giving the wrong impression
 about what you're talking about. All GC heap memory must naturally be garbage
 collected, so the issue is that it's allocated in the first place rather than
 the fact that it needs to be collected later.
Ah sorry for not seeing the other issue. I searched for "array initialization", but didn't come across that one. And yeah, I can see there being issues with the double meaning of garbage in terms of the garbage collector and garbage in terms of garbage data. I'll use different terminology in the future. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 14 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8820




PDT ---
 Ah sorry for not seeing the other issue. I searched for "array
initialization", but didn't come across that one.
Not a problem. It happens all the time. All it takes is someone wording things differently from how you think of the problem, and you won't find the issue. Just make sure that you put in a good faith effort to find an existing bug report before reporting it (as it sounds like you did). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 14 2012