On Mon, Oct 23, 2017 at 11:11 AM, Ben Barbour <ben.barb...@gmail.com> wrote: > > I wrote a small go program and each instance of it takes about 10MB when > executed, according to top's global usage counter (not sure if this is a > great way of measuring...). The details of what it does aren't important for > now, but this does prompt me to ask a few questions about go memory usage.
Using top is not a great way to measure memory usage for a Go program, as it will measure memory that the garbage collector has freed but that the runtime has not yet returned to the operating system. > 1) How much memory does the runtime use / preallocate? Can this be adjusted? It depends entirely on your program. The simplest way to think about it is that the runtime imposes an overhead on the memory that your program allocates for its own data structures. If you think of that overhead as 10%, you won't be very far wrong. > 2) Is any part of the runtime a shared object, or does each go program have a > fully independent copy? Can it be made to be shared, if it isn't? Normally no part of the runtime is a shared object, and each Go program will have a fully independent copy. You can make it a shared object on some systems by using the go build options -buildmode=shared and -linkshared. Doing this will save very little memory, as the Go runtime is small compared to the memory allocated by a typical Go program. The reasons for using shared objects are about using a single library update to fix (or break) a bunch of existing programs, not about saving memory. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.