Skip to content

Instantly share code, notes, and snippets.

@unixpickle
Created August 3, 2016 02:06
Show Gist options
  • Save unixpickle/5f6ecb0cc4c2cc5d40434764ba41b376 to your computer and use it in GitHub Desktop.
Save unixpickle/5f6ecb0cc4c2cc5d40434764ba41b376 to your computer and use it in GitHub Desktop.
Test memory allocation
package main
import (
"fmt"
"os"
"strconv"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "Usage:", os.Args[0], "<mem MB>")
os.Exit(1)
}
mb, err := strconv.Atoi(os.Args[1])
if err != nil {
fmt.Fprintln(os.Stderr, "Invalid size:", os.Args[1])
os.Exit(1)
}
fmt.Println("Allocating...")
data := make([]byte, mb*(1<<20))
fmt.Println("Overwriting with zeroes on loop...")
for {
for i := range data {
data[i] = 0
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment