Dynamic Memory Allocation - CS50 Shorts

preview_player
Показать описание
***

This is CS50, Harvard University's introduction to the intellectual enterprises of computer science and the art of programming.

***

HOW TO SUBSCRIBE

HOW TO TAKE CS50

HOW TO JOIN CS50 COMMUNITIES

HOW TO FOLLOW DAVID J. MALAN

***

CS50 SHOP

***

LICENSE

CC BY-NC-SA 4.0
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License

David J. Malan
Рекомендации по теме
Комментарии
Автор

The visual walkthrough at the end of this video was really helpful for understanding malloc and dereferencing. Thank you!

mollyexten
Автор

Additionally: You have to be very careful with dynamic memory when you don't have much memory available because it can be difficult to work out how much will be available at different parts of your program. Imagine a microcontroller with only 512 bytes of memory! It's common for embedded software companies to ban the use of dynamic memory in such microcontrollers because it is so easy to run out of memory and so hard to predict or fix problems. (In many situations the software design can be changed to use statically-assigned memory instead.)

This video also doesn't mention that as you malloc() and free() memory it will tend to get fragmented. If you then ask for a big chunk of memory it may not be able to find a contiguous block on the heap. (Contiguous means next to each other, like continuous.) In that case malloc() will return null but you could have more than half your memory technically available/unused. After malloc() returns null, you could then try requesting smaller chunks and managing having your data in different places.

It's also worth mentioning that modern languages usually use a "garbage collector" (e.g., in Java, Python, Dart) that will automatically free the memory for you when it works out that you no-longer need it. However, these languages usually don't have pointers and instead rely on other techniques.

ytubeleo
Автор

*cough *cough chrome....thanks for this video ♥️

rahulkumarroy
Автор

This video totally clarified the concepts of heap and stack. I thought they was separated chunks of memory, but actually they just differ in the usage (static or dynamic) of memory.

LuaneCarolineAquinoCavalcanti
Автор

Perfect explanation. I, however, don't ever see myself practically using this knowledge in my career as a web developer. I am taking CS50 to better myself as a programmer, these particularities of C just come along with it.

brak_
Автор

Everything was explained in the video really well, but I have one important question: What is the point of Dynamically Allocating Memory? Why would it be beneficial for us to allocate memory dynamically versus statically?

Ragnorok
Автор

thanks sir you are one of the best teacher i watced pointers, time complexity and few other basic video i fully understand the concept thanks alot

nothjg
Автор

On your judgment day, St. Peter will say:

[booming voice] "Doug Lloyd! Why did you never display "#include <stdlib.h>" on any of the slides in this video? Why did you spell it out vocally instead?"

Just a heads up. Be prepared.

jeffbowyer
Автор

Chrome 😂😂😂the browser which don't free the allocated memory makes the system slow & crash 😂

arunkumaralagarsamy
Автор

Just curious, can anyone explain what will exactly happen if you free the mallocked more than once?

nervous
Автор

'..browsers that shall remain nameless..' that part cracked me up a bit 😅

oteikwufrancis
Автор

Alright, nice explanation of what malloc() does, but I don´t understand why it is called dynamic memory allocation? Functionally "a" points to a "box" of memory, so does "b". The only difference I see is that the memory for "a" lives on the stack and the memory for "b" on the heap, but why does that matter?

martinder
Автор

Now I understand why I see so much "chrome" when I press Ctrl+Shift+Esc. :)

freelance-writer
Автор

thank you so much... love this explanation!

opay
Автор

Pls help me out...
As said in the video, if we allocate required memory during run time...then Wt is the difference... whether it's during compilation or DMA...we must know it's approx. Size right... except free() function which frees the memory...wt is the point of using DMA? Well, realloc serves a purpose cz, unlike in arrays...we can change i.e., increase size as per our requirement during runtime which is pretty useful...but wt about malloc or calloc?

UnKnown-lpgl
Автор

Which browser?


Sir, WHICH BROWSER?

vandanasonkar
Автор

ok i want to know the name of that browser

GhostDocs
Автор

Hi Doug, if b is a pointer variable, don’t pointer variables take up space in of themselves inside the computer’s memory? If so, why, at the very end of the video, when you say a = b; do pointer a and pointer b both point to the nameless box? Shouldn’t a point to the location in memory of the pointer variable b? Thanks Doug!

puturnamehere
Автор

4:36 Why is it written int (star)px instead of int(star) px?
(Notice the spacing between the two)

monkeylight
Автор

I could be mistaken but I recall in the lectures the notation free;

Are there situations where you don't need to specify what you are freeing?

Jack_______oh