www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11561] New: Built-in array .capacity returns 0 if array length is decreased

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

           Summary: Built-in array .capacity returns 0 if array length is
                    decreased
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: joseph.wakeling webdrake.net



2013-11-20 01:18:38 PST ---
Consider the following code:

    int[] arr;
    arr.length = 10;
    writeln(arr.length, "\t", arr.capacity);
    arr.length = 5;
    writeln(arr.length, "\t", arr.capacity);

Expected output:

    10    15
    5     n

... where n >= 5.

Actual output:

    10    15
    5     0

Since clearly the capacity of the array of length 5 _isn't_ 0, there is
something wrong in how the .capacity property is calculating its value after
the array length is reduced.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 20 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11561


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |INVALID



No, this is correct.  A capacity of zero simply means the slice cannot be
appended to.



If an append must reallocate a slice with no possibility of extension, then 0
is returned. This happens when the slice references a static array, or if
another slice references elements past the end of the current slice.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 20 2013
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11561




2013-11-20 03:11:37 PST ---
Fair enough.  Apologies for the misunderstanding.

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