v icon indicating copy to clipboard operation
v copied to clipboard

Use i64 as array length to support super large array

Open kbkpbot opened this issue 1 year ago • 1 comments

Describe the feature

Use datatype i64 instead of int as the array's len, offset and cap.

Use Case

Currently vlang use int as the array length, this will cause problem when try to using vlang in science computation. It does not support super large array.

for example, the following code will hang ...

module main

const (
        num_memory_trace = u64(1073741825)
)

fn main() {

        mut memory_trace := []u64{}
        println('try reading ${int(num_memory_trace)} memory traces')
        unsafe {
                memory_trace.grow_len(int(num_memory_trace))
        }
        println('grow done')
}

try reading 1073741825 memory traces
^C

by changing the 1073741825 to 1073741824, it will work.

try reading 1073741824 memory traces
grow done

Proposed Solution

replace int with i64 in array code.

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

Version used

0.3.3 524f7c3

Environment details (OS name and version, etc.)

V full version: V 0.3.3 4f532c0.524f7c3 OS: linux, Ubuntu 22.04.2 LTS Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz

getwd: /home/haha/v vexe: /HD/github/lang/v/v vexe mtime: 2023-04-13 09:18:04

vroot: OK, value: /HD/github/lang/v VMODULES: OK, value: /home/haha/.vmodules VTMP: OK, value: /tmp/v_1000

Git version: git version 2.34.1 Git vroot status: weekly.2023.15-8-g524f7c3e-dirty (10 commit(s) behind V master) .git/config present: true

CC version: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 thirdparty/tcc status: thirdparty-linux-amd64 12f392c3-dirty

kbkpbot avatar Apr 14 '23 14:04 kbkpbot

We have something like this on the 0.4 roadmap

 64/32 bit int depending on arch (will remove array.len limitation on 64 bit systems)

ArtemkaKun avatar Apr 14 '23 19:04 ArtemkaKun