How to allocate 1MB in Go

1 Answer

0 votes
package main

import "fmt"

func main() {
    data := make([]byte, 1024 * 1024) // 1MB = 1,048,576 bytes 

    // initialize 
    data[0] = 42 // Example usage

    fmt.Printf("Allocated %d bytes\n", len(data))
}



/*
run:

Allocated 1048576 bytes

*/

 



answered May 19, 2025 by avibootz

Related questions

3 answers 202 views
2 answers 152 views
3 answers 180 views
1 answer 131 views
131 views asked May 20, 2025 by avibootz
3 answers 197 views
3 answers 204 views
204 views asked May 20, 2025 by avibootz
...