1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin: improve support for large arrays ([]int{len: 1_000_000_000} now works), fix an arr.repeat() bug (#14294)

This commit is contained in:
Delyan Angelov
2022-05-04 18:42:06 +03:00
committed by GitHub
parent af8be14639
commit 1a4d9017e2
8 changed files with 216 additions and 150 deletions

View File

@@ -0,0 +1,19 @@
[direct_array_access]
fn test_big_int_array() {
dump(sizeof(isize))
mut maxn := 500_000_000 // try allocating ~2GB worth of integers on 32bit platforms
if sizeof(isize) > 4 {
maxn = 1_000_000_000 // 1 billion integers, when each is 4 bytes => require ~4GB
}
dump(maxn)
mut data := []int{len: maxn}
// ensure that all of the elements are written at least once, to prevent the OS from cheating:
for i in 0 .. maxn {
data[i] = i
}
assert data[0] == 0
assert data[maxn - 1] == maxn - 1
dump(data#[0..10])
dump(data#[-10..])
}