[Golang] Queue

  Рет қаралды 734

Panpito

Panpito

Күн бұрын

Today, the queue data structure!
Twitter: / panpit0
• 🧠 DESIGN PATTERNS 🧠
• 🎥 GO FOR IT! 🎥
• 📚 PUBLISHING YOUR LIBR...
• 💥 ALL ABOUT GO 💥
---
Golang version: 1.19
IDE: Goland
OS: Windows
Accent: French

Пікірлер: 6
@finicuro2744
@finicuro2744 Жыл бұрын
what a surprise, you're back!
@fringefringe7282
@fringefringe7282 Жыл бұрын
Hm. Doesnt Pop() method have a memory leak? You are re-slicing which means that underneath new slice will reference the same array, just wont have access to 0th element. With large queues and complex elements (ie. structs) this can pose a problem. Would you agree? Many thanks.
@panpit0
@panpit0 Жыл бұрын
I don't think it's memory leak as in you can access to that memory address by mistake, the original slice still holds the value in memory, it is just a delayed garbage collection. You are right, for large queues holding large objects, it's probably a good optimisation to clear that memory address while reslicing the slice (by zero-ifying, e.g 0 for an int, "" for a string etc). Does that make sense to you? Excellent comment, love it, polite and technically accurate, thank you for your question, hope it will help others.
@fringefringe7282
@fringefringe7282 Жыл бұрын
@@panpit0 Hm, I dont know what you mean by "the original slice still holds the value". In line 19 (queue.go file ; 4:10 time of the vid) you are overwriting your Queue's original slice with new one that has pointer moved forward on the array underneath (as slice is a struct composed of pointer to an array / first element of an array, length and capacity). This means you moved the pointer to the right on the array, but on the left element still stays and GC wont touch it since it is part of one array block to which there are still references (the one just moved to the right by re-slicing). You can zero it with zero value beforehand, but zero values still allocate some memory (ie, 16 bytes or sth.). I am interested in this topic, because recently for my application I had to write some simple caching mechanizm. That got me into this whole rabbit hole of slices. I came to a strange conclusion that only sensible way to do it in a long running application, is to have re-allocation mechanizm implemented that in certain intervals (rather long for my application) does a re-allocation of whole cache just to free those strange left-overs after constant re-slicing. Maybe I am wrong, maybe I dont understand something. I am just a Unix guy that took an adventurous route :)
@fringefringe7282
@fringefringe7282 Жыл бұрын
BTW, Many thanks for all the videos. I am learning a lot from those design patterns vids.
@panpit0
@panpit0 Жыл бұрын
I’m on holiday, I’ll reply to you later next week!
[Golang] Memento
32:02
Panpito
Рет қаралды 764
[Golang] Stack
7:41
Panpito
Рет қаралды 767
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 51 МЛН
How Many Balloons Does It Take To Fly?
00:18
MrBeast
Рет қаралды 129 МЛН
HOW DID HE WIN? 😱
00:33
Topper Guild
Рет қаралды 45 МЛН
A clash of kindness and indifference #shorts
00:17
Fabiosa Best Lifehacks
Рет қаралды 70 МЛН
[Golang] Adapter
18:25
Panpito
Рет қаралды 2,1 М.
Golang's Mocking Techniques - Kyle Yost | hatchpad Huddle
41:20
"The Life & Death of htmx" by Alexander Petros at Big Sky Dev Con 2024
23:01
Montana Programmers
Рет қаралды 36 М.
RabbitMQ in 100 Seconds
2:31
Fireship
Рет қаралды 572 М.
Golang Channels Or Wait Groups? Let Me Explain.
18:32
Anthony GG
Рет қаралды 19 М.
Enums considered harmful
9:23
Matt Pocock
Рет қаралды 198 М.
[Golang] Composite
18:56
Panpito
Рет қаралды 709
College interview question that confused most students
10:22
Higher Mathematics
Рет қаралды 6 М.
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 51 МЛН