在 Julia 中逐行检查内存分配

check memory allocation line by line in Julia

我想检查每一行代码中的内存分配。我用了@time,我得到了 5.381438 seconds (2.19 M allocations: 809.021 MiB, 1.08% gc time)

(2.19 M allocations: 809.021 MiB, 1.08% gc time) 是什么意思?

我的某些输入代码内存不足,我知道内存分配有问题,如何逐行检查内存分配?

The total amount of allocation can be measured with @time and @allocated, and specific lines triggering allocation can often be inferred from profiling via the cost of garbage collection that these lines incur.

However, sometimes it is more efficient to directly measure the amount of memory allocated by each line of code.

To measure allocation line-by-line, start Julia with the --track-allocation=<setting> command-line option.

When you quit Julia, the cumulative results are written to text files with .mem appended after the file name, residing in the same directory as the source file.

Each line lists the total number of bytes allocated.