Thread overview
[Issue 15481] GC profiler thinks reducing array.length triggers reallocation
Dec 28, 2015
ag0aep6g@gmail.com
Dec 28, 2015
Valentin Milea
Apr 20, 2017
Leandro Lucarella
Apr 20, 2017
Leandro Lucarella
Oct 28, 2022
RazvanN
December 28, 2015
https://issues.dlang.org/show_bug.cgi?id=15481

ag0aep6g@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ag0aep6g@gmail.com
            Summary|Reducing array.length       |GC profiler thinks reducing
                   |triggers reallocation       |array.length triggers
                   |                            |reallocation

--- Comment #1 from ag0aep6g@gmail.com ---
This is a bug in the GC profiler. The array is not relocated. You can check by comparing the pointers:

----
void main()
{
    int[] arr;
    arr.length = 7;
    int* p = arr.ptr;
    arr.length = 6;
    assert(arr.ptr == p); /* passes */
}
----

I'm changing the title of this issue accordingly.

--
December 28, 2015
https://issues.dlang.org/show_bug.cgi?id=15481

--- Comment #2 from Valentin Milea <valentin.milea@gmail.com> ---
Maybe the reallocation function is called and returns the same buffer. But why call it in the first place, if reducing array length is supposed to be _equivalent_ to slicing?

--
April 20, 2017
https://issues.dlang.org/show_bug.cgi?id=15481

Leandro Lucarella <leandro.lucarella@sociomantic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |leandro.lucarella@sociomant
                   |                            |ic.com
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=17294

--
April 20, 2017
https://issues.dlang.org/show_bug.cgi?id=15481

Leandro Lucarella <leandro.lucarella@sociomantic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=16280

--
October 28, 2022
https://issues.dlang.org/show_bug.cgi?id=15481

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |FIXED

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
Running the example today yields:

bytes allocated, allocations, type, function, file:line
             32»              1»int[] D main test.d:3

So this seems to have been fixed by: https://github.com/dlang/druntime/pull/2607

--