Tap to unmute

How to properly deal with dynamically allocated memory

  Рет қаралды 9,362

CodeVault

CodeVault

Күн бұрын

Пікірлер: 18
@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!
@weeb2006
@weeb2006 2 жыл бұрын
in the other video, malloc() was type casted with (int*) but why it wasn't necessary in 1:18?
@CodeVault
@CodeVault 2 жыл бұрын
In C it's optional to type cast the result of malloc. I may be inconsistent in some videos at times
@nandorboda8049
@nandorboda8049 Ай бұрын
These vids are so usefull!
@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
@matteopisati9966
@matteopisati9966 3 жыл бұрын
thank you very much !
@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
Рет қаралды 74 М.
When to free memory in C
13:45
CodeVault
Рет қаралды 10 М.
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН
How to return and pass a struct to a function
13:30
CodeVault
Рет қаралды 31 М.
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,5 МЛН
Writing Code That Runs FAST on a GPU
15:32
Low Level
Рет қаралды 574 М.
printf(MEMORY) | How to print memory to the console
12:18
CodeVault
Рет қаралды 10 М.
Dynamically allocated multi-dimensional arrays in C
14:17
CodeVault
Рет қаралды 45 М.
Good practice for freeing memory in C
8:17
CodeVault
Рет қаралды 14 М.
Dynamically Allocate A 2D Array | C Programming Tutorial
15:58
Portfolio Courses
Рет қаралды 42 М.
Difference between arrays and pointers in C
11:23
CodeVault
Рет қаралды 33 М.
Difference between memmove and memcpy
9:15
CodeVault
Рет қаралды 26 М.
you will never ask about pointers again after watching this video
8:03
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН