Limit memory allocation in Go language?

I find a way to limit memory usage in Go. My Go-based application has big data that needs to be loaded into main memory, so I want to limit the maximum process memory size to the size specified by the user.

In C, in fact, I am accumulating malloc'ed memory sizes for this, but I don’t know how to do the same in Go.

Please let me know if there is a way to do this.

Thanks.

+6
source share
3 answers

The Go garbage collector is not deterministic and conservative. Therefore, using the variable runtime.MemStats will not be accurate for your purpose.

Correct the approximate use of memory by setting the maximum size of the data that you intend to simultaneously load into the process using user input.

+4
source

Perhaps you want to use ulimit in conjunction with a transition code?

+1
source

Besides runtime.MemStats, you can use gosigar to monitor system memory.

0
source

Source: https://habr.com/ru/post/891712/


All Articles