Загрузка...

Golang Interview Questions - Arrays and Slices in Go

Golang Interview Questions. how arrays and slices work in Go, including creation, memory behavior, performance considerations, and real-world usage patterns.

This video covers how to create arrays using var, literals, inferred length (...), sparse arrays, and multi-dimensional arrays. You’ll also understand that arrays are value types—assignments and function calls copy the entire array, which can impact performance.

We explore array comparison rules, when arrays should be preferred over slices (fixed-size data like hashes, IP addresses, matrices, and map keys), and why slices are more commonly used in dynamic scenarios.

You’ll learn what slices are internally (pointer, length, capacity), how to create them (var, literals, make, slicing arrays), and the key difference between nil and empty slices—especially in JSON encoding (null vs []).
00:00 Arrays & Slices in Go (Overview)
00:00:07 Creating arrays in Go
00:00:58 Array assignment & value semantics
00:01:35 Comparing arrays
00:06:45 Slice capacity & pre-allocation (make)
00:07:09 copy() function explained
00:07:40 Deleting elements from slices
00:08:19 Inserting elements into slices
00:08:59 Shared backing array trap
00:09:45 Slice memory leaks (small slice issue)
00:10:20 Pointer issues when shrinking slices
00:11:03 slices package (Go 1.21+ utilities)
00:11:39 Looping through slices
00:12:11 Range loop common mistake
00:12:48 Range + closures change (Go 1.22)
00:13:27 Two-dimensional slices
00:14:04 Filtering slices efficiently (no allocation)
00:14:43 Stack implementation using slices
00:15:12 Why slices are bad for queues
00:15:44 Splitting slices into batches
00:16:20 Clearing slices efficiently
00:17:01 slices.Grow usage
00:17:24 slices.Clip (memory optimization)
00:17:49 Array ↔ Slice conversions
00:18:29 Strings vs Bytes vs Runes
00:19:09 Passing slices to functions
00:19:52 Unsafe slice tricks (advanced)
00:20:45 Builder pattern (strings.Builder)
00:21:22 sync.Pool with slices (performance)
00:22:03 New range feature (Go 1.22)
00:22:33 Common mistakes & summary

Видео Golang Interview Questions - Arrays and Slices in Go канала Reza Mirjahan
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять