mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-14 09:11:16 +00:00
first
This commit is contained in:
17
course/1-intro/exercises/9a-lang_compare_memory/readme.md
Normal file
17
course/1-intro/exercises/9a-lang_compare_memory/readme.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Go programs are easy on memory
|
||||
|
||||
Go programs are fairly lightweight. Each program includes a small amount of "extra" code that's included in the executable binary. This extra code is called the [Go Runtime](https://go.dev/doc/faq#runtime). One of the purposes of the Go runtime is to cleanup unused memory at runtime.
|
||||
|
||||
In other words, the Go compiler includes a small amount of extra logic in every Go program to make it easier for developers to write code that's memory efficient.
|
||||
|
||||
## Comparison
|
||||
|
||||
As a general rule Java programs use *more* memory than comparable Go programs because Go doesn't use an entire virtual machine to run its programs, just a small runtime. The Go runtime is small enough that it is included directly in each Go program's compiled machine code.
|
||||
|
||||
As another general rule Rust and C++ programs use slightly *less* memory than Go programs because more control is given to the developer to optimize memory usage of the program. The Go runtime just handles it for us automatically.
|
||||
|
||||
## Idle memory usage
|
||||
|
||||

|
||||
|
||||
In the chart above, [Dexter Darwich compares the memory usage](https://medium.com/@dexterdarwich/comparison-between-java-go-and-rust-fdb21bd5fb7c) of three *very* simple programs written in Java, Go, and Rust. As you can see, Go and Rust use *very* little memory when compared to Java.
|
||||
Reference in New Issue
Block a user