Created
August 3, 2016 02:06
-
-
Save unixpickle/5f6ecb0cc4c2cc5d40434764ba41b376 to your computer and use it in GitHub Desktop.
Test memory allocation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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