Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

Using make() in Go - Creating and Initializing Slices, Maps, and Channels

Gary Clarke via YouTube

Overview

Coursera Flash Sale
40% Off Coursera Plus for 3 Months!
Grab it
Learn how to properly initialize slices and maps in Go using the built-in make() function to avoid runtime panics and control memory allocation. Discover the critical difference between declaring variables with var (which creates nil values) and creating them with make() (which allocates and initializes the underlying data structures). Master creating slices with specific length and capacity parameters, understand how length and capacity work together for optimal performance, and learn to initialize maps so they're ready to accept key-value pairs immediately. Explore the conceptual foundation of how make() allocates memory for Go's core data structures including slices, maps, and channels, and understand when each approach is appropriate for different use cases. Gain practical experience through hands-on examples that demonstrate proper initialization techniques and learn to pre-allocate capacity for better performance in memory-sensitive applications.

Syllabus

Using make() in Go

Taught by

Gary Clarke

Reviews

Start your review of Using make() in Go - Creating and Initializing Slices, Maps, and Channels

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.