👾 Geek Engineers
539 subscribers
51 photos
42 files
330 links
👾 Extremist software engineering guidance for Geeks.

Website:
https://geekengineers.netlify.app

Github:
https://github.com/geekengineers
https://github.com/tahadostifam

Community:
@geek_engineers_community
Download Telegram
Make:

Purpose: Allocates and initializes memory for specific data structures like slices, maps, and channels.

Return type: The specific data structure type (e.g., []T, map[K]V, chan T).

Initialization: The allocated memory is initialized with default values depending on the data structure type :

- Slices: Empty slice with a nil pointer and capacity of 0.
- Maps: Empty map with a nil pointer.
- Channels: Unbuffered channel that can block operations until data is available or space becomes free.

Usage: Creating new instances of slices, maps, and channels for data storage and communication.

Example:
slice := make([]int, 5) // Creates a slice of integers with a capacity of 5 (can hold up to 5 elements)
myMap := make(map[string]string) // Creates an empty map to store string key-value pairs
ch := make(chan int) // Creates an unbuffered channel for integer communication
Differences between new and make in Go
👾 Geek Engineers pinned «https://www.youtube.com/watch?v=f6kdp27TYZs»