How to properly deal with dynamically allocated memory

  Рет қаралды 8,741

CodeVault

CodeVault

5 жыл бұрын

I'm sure you know about malloc. In this video we'll take a look at functions that are so so useful but are not usually talked about and few people know about them.

Пікірлер: 17
@lucasferrini7063
@lucasferrini7063 3 жыл бұрын
I would like to add something that happened to me while using realloc. It's wise to use a temp variable to store the address that realloc returns, because it can happen that due to memory fragmentation you don't have enough space to expand your array, which results in realloc returning NULL. You wouldn't only be unable to store anything, but you would actually also loose the memory address of your array and produce a memory leak, as the original memory segment is still reserved, just not pointed to by anything.
@CodeVault
@CodeVault 3 жыл бұрын
Oh, that's a good point, thanks!
@mavrix2356
@mavrix2356 4 жыл бұрын
Thanks for the Clean and clear explanation..
@davidliverman4742
@davidliverman4742 2 жыл бұрын
Thanks for your time. God bless!
@matteopisati9966
@matteopisati9966 2 жыл бұрын
thank you very much !
@anaalcazar6533
@anaalcazar6533 3 жыл бұрын
Hey there ! plz I need ur help. When we define a binary search tree with a root that contains INFINITY value does it mean that the right subtree is nonexistent ?
@CodeVault
@CodeVault 3 жыл бұрын
I guess? Why would you ever do that to a binary tree though? You usually want to balance those trees so they are efficient
@weeb2006
@weeb2006 2 жыл бұрын
in the other video, malloc() was type casted with (int*) but why it wasn't necessary in 1:18?
@CodeVault
@CodeVault Жыл бұрын
In C it's optional to type cast the result of malloc. I may be inconsistent in some videos at times
@chenwu9788
@chenwu9788 2 жыл бұрын
do you have videos talking about vector and matrix computations?
@CodeVault
@CodeVault 2 жыл бұрын
No. There is a library I used in the past called kazmath: github.com/Kazade/kazmath
@chenwu9788
@chenwu9788 2 жыл бұрын
@@CodeVault many thanks, do you know if the lib can do complex matrix /vector calculations
@CodeVault
@CodeVault 2 жыл бұрын
I guess it's limited to matrices and vectors of maximum size 4. Since this is more of a computer graphics library. For actual math applications there is this: www.gnu.org/software/gsl/ It probably has whatever you need in there, you have to read the documentation a bit since it can be quite complex to use
@chenwu9788
@chenwu9788 2 жыл бұрын
how to do arr substract p using for loop, and without using for loop?
@CodeVault
@CodeVault 2 жыл бұрын
With just a for loop: for (int i = 0; i < 64; i++) arr[i] -= p; I don't know how you'd do it without a for loop
@chenwu9788
@chenwu9788 2 жыл бұрын
@@CodeVault does c have array/matrix lib for matrix calculation?
@CodeVault
@CodeVault 2 жыл бұрын
In its own standard library? No
How to use dynamically allocated arrays
11:29
CodeVault
Рет қаралды 72 М.
Difference between arrays and pointers in C
11:23
CodeVault
Рет қаралды 32 М.
Playing hide and seek with my dog 🐶
00:25
Zach King
Рет қаралды 36 МЛН
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 6 МЛН
小蚂蚁被感动了!火影忍者 #佐助 #家庭
00:54
火影忍者一家
Рет қаралды 28 МЛН
When to free memory in C
13:45
CodeVault
Рет қаралды 9 М.
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,4 МЛН
TUTO C - #17 L'allocation de mémoire dynamique (malloc)
18:52
Boris ('PrimFX')
Рет қаралды 45 М.
Dereferencing in C
10:29
CodeVault
Рет қаралды 10 М.
Dynamic Memory Allocation | C Programming Tutorial
31:51
Portfolio Courses
Рет қаралды 80 М.
Enter The Arena: Simplifying Memory Management (2023)
1:47:50
Ryan Fleury
Рет қаралды 31 М.
Difference between memmove and memcpy
9:15
CodeVault
Рет қаралды 24 М.
printf(MEMORY) | How to print memory to the console
12:18
CodeVault
Рет қаралды 9 М.
Lecture 6: Version Control (git) (2020)
1:25:00
Missing Semester
Рет қаралды 671 М.
Что делать если в телефон попала вода?
0:17
Лена Тропоцел
Рет қаралды 3,3 МЛН
📱магазин техники в 2014 vs 2024
0:41
djetics
Рет қаралды 637 М.
Tag him😳💕 #miniphone #iphone #samsung #smartphone #fy
0:11
Pockify™
Рет қаралды 4,2 МЛН