perl - array of integers using way too much memory?

后端 未结 8 697
我寻月下人不归
我寻月下人不归 2021-01-18 06:05

When I run the following script:

my @arr = [1..5000000];

for($i=0; $i<5000000; $i++) {
        $arr[$i] = $i;
        if($i % 1000000 == 0) {
                    


        
8条回答
  •  北荒
    北荒 (楼主)
    2021-01-18 06:16

    All Perl values are represented internally as perl scalars, which consume way more memory than a simple int. Even if the scalar is only holding an int. Even if the scalar is undef!

    As others have suggested, PDL may be something to look at if you really want to work with huge arrays of this sort.

提交回复
热议问题