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:
19
vlib/v/tests/big_array_allocation_test.v
Normal file
19
vlib/v/tests/big_array_allocation_test.v
Normal 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..])
|
||||
}
|
Reference in New Issue
Block a user