In-place extension of arrays only for certain alignment?
Salih Dincer
salihdb at hotmail.com
Wed Aug 17 00:17:32 UTC 2022
On Tuesday, 16 August 2022 at 18:11:54 UTC, Ali Çehreli wrote:
> ```d
> version (good) {
> // Dropping front elements equaling 2048 bytes works.
> // (Likely a GC magic constant.)
>
> enum magic = 2048;
> enum elementsPerPage = magic / S.sizeof;
>
> if (arr.length == elementsPerPage) {
> arr = arr[elementsPerPage..$];
> }
> }
> ```
First I tried it on an older version (2.0.87). And with
version(good) I got interesting results:
```d
(length == 1, capacity: 2031 -> 6127)
i = 4079, 8175
(length == 2, capacity: 1015 -> 3063)
i = 2039, 4087, 6135, 8183
(length == 3, null)
i > 10.000 = ?
(length == 4, capacity: 507 -> 1531)
i = 1019, 2043, 3067, 4091, 5115, 6139, 7163, 8187, 9211
(length == 5, 6, 7..., null)
i > 10.000 = ?
```
For some reason the capacity changed frequently when data.length
== 4 . And I didn't see a result in 3, 5, 6, 7 since I tested
less than 10k loops. I got more interesting results with the
extra version:
```d
version(extra) arr.length++; /*
2087
291 elements, capacity: 582 -> 1167, ptr: 7F1306346010
1169 elements, capacity: 2338 -> 4093, ptr: 7F1306346010
2339 elements, capacity: 4678 -> 8189, ptr: 7F1306346010
4387 elements, capacity: 8774 -> 14626, ptr: 7F1306346010
7313 elements, capacity: 14626 -> 23403, ptr: 7F1306346010
Process finished.
*/
```
version(neither) is concurrent with i:
```d
(length == 1, capacity: i)
i = 4079, 8175..16367
(length == 2)
i = 2039, 4087, 8183..14327
(length == 3, capacity: i)
i = 1359, 2725, 5455, 9551..16378
(length == 4, capacity: i)
i = 1019, 2043, 4091, 7163..12283
(length == 5, capacity: i)
i = 815, 1635, 3273, 5731, 9827..16380
```
SDB at 79
More information about the Digitalmars-d-learn
mailing list