[Issue 15481] New: Reducing array.length triggers reallocation
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Dec 27 22:57:19 PST 2015
https://issues.dlang.org/show_bug.cgi?id=15481
Issue ID: 15481
Summary: Reducing array.length triggers reallocation
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: valentin.milea at gmail.com
According to spec: "If the new array length is shorter, the array is not
reallocated, and no data is copied. It is equivalent to slicing the array".
This is contradicted by:
void main() {
int[] arr;
arr.length = 7;
arr.length = 6; // not ok -- allocation reported
arr = arr[0..5]; // ok -- no allocation
}
// dmd -profile=gc test.d
// (DMD32 D Compiler v2.069.2)
// -------------------------------------------------------
// bytes allocated, allocations, type, function, file:line
// 28 1 int[] D main test.d:3
// 24 1 int[] D main test.d:4
--
More information about the Digitalmars-d-bugs
mailing list