Can you use dynamic data types in C?

  Рет қаралды 1,137

Eric O Meehan

Eric O Meehan

Күн бұрын

Пікірлер: 6
@hasanalattar9561
@hasanalattar9561 3 жыл бұрын
Hi Eric im not sure which part @6:22 that was working but if you are refering to destroying node that contains data and returning their pointer .. then it can happen and work .. its just called dangling pointer .. the os is responsible to allocate you the heap memory when u destroy it it doesnt change the actual memory.. its just free to use again by you or other softwares ..
@eom-dev
@eom-dev 3 жыл бұрын
Interesting, thanks for letting me know!
@EverythingExceptThat
@EverythingExceptThat 4 жыл бұрын
Great video! I’d be interested to hear more about where the performance penalty comes from here, is it just because of more dynamic allocations?
@eom-dev
@eom-dev 4 жыл бұрын
That is exactly right! Allocating items to the stack requires a single CPU command, whereas allocating to the heap requires several. I have implemented dynamic allocation twice here: first for the nodes themselves, and then again for the data contained in the nodes. If I was using a linked list that could only contain integers, I would be able to store the object's data within the same action as the one that allocates space for the node. Essentially, calling malloc once instead of twice. What is interesting is that, despite this performance cost, the program still is faster than the C++ version! I am going to make a video on this soon, but using a class template in C++ is actually slower than calling malloc twice. The difference is minute but measurable, so here again we are faced with a tradeoff between convenience and performance!
@EverythingExceptThat
@EverythingExceptThat 4 жыл бұрын
@@eom-dev Interesting, thank you!
@naghs2726
@naghs2726 Жыл бұрын
This wouldve been a perfect place to use macros
Dynamic Memory Allocation | C Programming Tutorial
31:51
Portfolio Courses
Рет қаралды 99 М.
CppCon 2014: Mike Acton "Data-Oriented Design and C++"
1:27:46
GIANT Gummy Worm #shorts
0:42
Mr DegrEE
Рет қаралды 152 МЛН
Hilarious FAKE TONGUE Prank by WEDNESDAY😏🖤
0:39
La La Life Shorts
Рет қаралды 44 МЛН
Understanding Ownership in Rust
25:30
Let's Get Rusty
Рет қаралды 280 М.
Templates in C++
17:58
The Cherno
Рет қаралды 612 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
Pipes and Named Pipes in C
16:12
Eric O Meehan
Рет қаралды 4,8 М.
you will never ask about pointers again after watching this video
8:03
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 200 М.
Reading and Writing Raw Bytes to Files in C
18:12
Eric O Meehan
Рет қаралды 10 М.
"Simple Made Easy" - Rich Hickey (2011)
1:01:39
Strange Loop Conference
Рет қаралды 110 М.
Creating a Web Server from Scratch in C
46:54
Eric O Meehan
Рет қаралды 79 М.
Stack vs Heap Memory in C++
19:31
The Cherno
Рет қаралды 591 М.