Dynamic memory allocation in C - malloc calloc realloc free

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 พ.ย. 2024

ความคิดเห็น • 544

  • @aydinlenma2416
    @aydinlenma2416 ปีที่แล้ว +42

    Almost 10 years and still this is the only video that made me understand dynamic memory allocation in c

  • @aburridohp
    @aburridohp 10 ปีที่แล้ว +387

    Sir. Thanks for this video. I am a Computer Science student from USA, and the only thing I can say is that my professor should be watching this video also. You saved me to complete my assingment, but the most important thing is that I finally learned the topic which is more important to me.
    Greetings from Miami.
    Best Regards

    • @mycodeschool
      @mycodeschool  10 ปีที่แล้ว +21

      aburridohp You are most welcome :)

    • @srix01
      @srix01 9 ปีที่แล้ว +5

      +mycodeschool really awesome for beginners also

    • @masbro1901
      @masbro1901 8 ปีที่แล้ว +5

      +aburridohp me too, this video help me a lot. i'am also a computer science student, regards from indonesia.

    • @theamjolnir9641
      @theamjolnir9641 6 ปีที่แล้ว

      This so much!

    • @jiteshsharma4692
      @jiteshsharma4692 6 ปีที่แล้ว +1

      mycodeschool ....awesome video... This video is much much better than other local books.. And college teachers/ professors .....thank you mycodeschool

  • @ankitgupta8797
    @ankitgupta8797 7 ปีที่แล้ว +16

    You are actually explaining the most complex things in the simplest way. I think every book on C should contain a reference to your videos.

  • @KT22672
    @KT22672 วันที่ผ่านมา

    I sit in class for 75 minutes twice a week and this man explains it better in 17 minutes

  • @nakarelka
    @nakarelka 10 ปีที่แล้ว +246

    Thank you very much for all your videos. I really feel like my teacher should learn from you, it's amazing how you can, in 17 minutes, explain something she's trying to explain in 3 hours. And she fails every time. Too bad I haven't found your videos earlier! :)

    • @mycodeschool
      @mycodeschool  10 ปีที่แล้ว +27

      Thanks a lot Natália Karelová

    • @nixondutta8192
      @nixondutta8192 9 ปีที่แล้ว +12

      sir same compliments from me too. it's a shame i didn't find your videos earlier.

    • @darkrayc
      @darkrayc 8 ปีที่แล้ว +4

      Wow I wish I found these at least a few months ago... then my assignments would have been a piece of cake. :'(

    • @utsavprabhakar5072
      @utsavprabhakar5072 8 ปีที่แล้ว +4

      feel absolutely the same thing. I could have passed my mid-sem examinations had I had access to these videos earlier :3 thanks a lot :D

    • @prakharkumar7368
      @prakharkumar7368 7 ปีที่แล้ว

      Natália Karelová

  • @rachanacitc
    @rachanacitc 7 ปีที่แล้ว +2

    SO FAR, ONE OF THE BEST EXPLANATIONS OF DYNAMIC MEMORY. MY CONCEPTS ARE TOTALLY CLEAR, ALL THANKS TO YOU :) WE USUALLY SHY AWAY OR RATHER FEAR DYNAMIC MEMORY ALLOCATION, BUT AFTER WATCHING THIS VIDEO, MY PERCEPTION HAS SURELY CHANGED.

  • @daevyd100
    @daevyd100 11 ปีที่แล้ว +1

    Your whole series on pointers in C is an absolute goldmine!

  • @randomvideos5407
    @randomvideos5407 4 ปีที่แล้ว +9

    learning is so fun when you learn it from the right people

  • @SnehaVernekar
    @SnehaVernekar 9 ปีที่แล้ว +41

    thanks a lot ! after 3 yrs in engineering now i am understanding the basic concepts being in final year !

    • @tripleh5825
      @tripleh5825 9 ปีที่แล้ว +9

      +Sneha Vernekar Your comment makes me feel a lot luckier as I am still in my second year and sir has saved me the effort

    • @SnehaVernekar
      @SnehaVernekar 9 ปีที่แล้ว +2

      Triple H nice :) make the best use of these videos ! get the concepts cleared right from the beginning :)

    • @tripleh5825
      @tripleh5825 9 ปีที่แล้ว +2

      +Sneha Vernekar Sure. Your words mean a lot coming from an experience senior :)

    • @StockStalker.
      @StockStalker. 5 ปีที่แล้ว +2

      I am a 3rd semester student and i think i have come to right place

    • @Anonymous-mz9un
      @Anonymous-mz9un 3 ปีที่แล้ว

      And your comment makes me feel bad coz I'm a s/w engineer and still unclear about the subject.

  • @SleetDrops
    @SleetDrops 5 ปีที่แล้ว +1

    I have learned much more from cramming to your videos in 4 hours than my university prof's teachings that stretch over months.
    sir mycodeschool, you is the realest

  • @tapionevalainen6776
    @tapionevalainen6776 5 ปีที่แล้ว +2

    I have watched a fair amount of tutorials in a wide range of topics over the years. This series has to be, hands down, the best one there is. Amazing job dude, I sincerely hope you are a teacher because you are the natural talent.

  • @latias9628
    @latias9628 4 ปีที่แล้ว +1

    I just wanted to say thank you! I'm relearning some stuff I'm rusty on for my new job and I appreciate greatly the fact that you share all of this knowledge for free for us.

  • @namanshah2688
    @namanshah2688 3 ปีที่แล้ว +1

    after so many failed attempts to learn basic programmng from different platforms now i can certainly say this is one of the best platforms to learn basics thanks to entire team for making such an amazing series .

  • @thestarinthesky_
    @thestarinthesky_ 4 ปีที่แล้ว +1

    You are by far the MOST
    amazing teacher in TH-cam! Thank you so much. I wish you could get back here soon. We, cs students, really really need your knowledge!

  • @jacobgriner9569
    @jacobgriner9569 6 ปีที่แล้ว +2

    I love your videos!!! My teacher from palm beach state college doesn't explain nearly as well as you and I'm so lucky to have found your vids. You're a life saver. I'm gonna spread the word so that more people can know about your vids when they are confused in C.
    Greetings from Boca Raton, Florida.

  • @kiranmathews1953
    @kiranmathews1953 6 ปีที่แล้ว +1

    The information inside those 17 videos is the minimum requirement for any programmer.
    Good job.

  • @zephyr.huseynov
    @zephyr.huseynov 3 ปีที่แล้ว

    The best explanation i have ever seen.. Greeting from Azerbaijan 🇦🇿

  • @YorozuyaNeesan2010
    @YorozuyaNeesan2010 8 ปีที่แล้ว +3

    Watching your videos is an excellent accompaniment to reading my textbook, which is sometimes so unclear, I could cry lol. Thank you so much!

  • @lucasa8710
    @lucasa8710 2 ปีที่แล้ว

    9 year later, and it the most helpful channel on this topic, great work

  • @terrykoontz347
    @terrykoontz347 7 ปีที่แล้ว +1

    One of the best teacher ever. Thanks for sharing your knowledge!

  • @yuanwang9896
    @yuanwang9896 4 ปีที่แล้ว +4

    Thanks so much. I am a new grad to CS major and I just learn "coding" in python, matlab before in kinda math major. What we learnt about C in math major is so similar to learning python, just in another syntax, but actually they are so different! This series saved my life and really let me know deeper in C. Thanks again!

  • @arvindramanathan329
    @arvindramanathan329 2 ปีที่แล้ว

    This channel is the best that I have found on these topics, thanks for sharing this. Again it proves the subject is not complex it is the way it is explained that makes it complex.

  • @Capt_Saicin
    @Capt_Saicin 6 ปีที่แล้ว +1

    Man I am actually really impressed with this explanation usually I find TH-cam tutorials for coding super convoluted, but this one was very clear and precise. Good job

  • @praxisdev1884
    @praxisdev1884 7 ปีที่แล้ว

    You've made the topics of pointers and dynamic memory allocation crystal clear for me. You're a rockstar. Thank you.

  • @SazzadHossain-su1vb
    @SazzadHossain-su1vb 5 ปีที่แล้ว

    Why some people dislike this kind of educational content. Thanks bro it helps me a lot.

  • @faisaldj
    @faisaldj 11 ปีที่แล้ว +5

    I am in a German University and I must admit that you are an excellent teacher,,,keep it up

  • @GabrielVasile
    @GabrielVasile 5 ปีที่แล้ว +43

    malloc -> Memory ALLOCation
    calloc -> Continuous ALLOCation
    realloc -> REALLOCation

    • @fizqialfairuz5744
      @fizqialfairuz5744 4 ปีที่แล้ว +7

      Calloc actually stands for contiguous allocation.

  • @coffle1
    @coffle1 10 ปีที่แล้ว +3

    Great video ! C was my first programming language, and when I was first learning it I had no idea how to use malloc, calloc, and realloc, and just ended up never learning it lol. Thankfully when I decided to try and learn exactly what these functions do, your video was able to provide an easy to understand explanation.

  • @yoitsrob
    @yoitsrob 6 ปีที่แล้ว

    Great video, this is by far the best tutorial i have found on line after hours of reading articles and watching videos

  • @devendramishra4197
    @devendramishra4197 6 ปีที่แล้ว

    I think i could have paid my college fee to you for this teaching ...u are awesome ..My college professor's should see these video to learn actual c/c++...and companies are hoping from us to be a good programmer without such a good depth knowledge..

  • @ChildofDestiny22
    @ChildofDestiny22 8 ปีที่แล้ว

    Simple, detailed, no bullshit explanation, i wish every teacher in my university is like you. THANKS ALOT!!

  • @AakarshDarla
    @AakarshDarla 8 ปีที่แล้ว +9

    at 9:55 it's perfectly fine to declare A[n] as an integer array , works perfect in my codeblocks compiler !

    • @adityachawla2163
      @adityachawla2163 8 ปีที่แล้ว +1

      Really? never heard of that before. I don't even believe that smh

    • @puturavindrawiguna3025
      @puturavindrawiguna3025 3 ปีที่แล้ว

      Yes, indeed sir, I was thinking the same thing. Like I've written codes that uses a variable to declare the size of an array, and it works fine. So, I am guessing this is more of a compiler thing? rather than the C language itself? Like in some compiler you cant do that, and in other, we can.

    • @gamoholic7653
      @gamoholic7653 3 ปีที่แล้ว

      @@puturavindrawiguna3025 I guess it's legal in C++ but I never tried in C. Can you please try and share the observations with me...

    • @adityavsx
      @adityavsx 3 ปีที่แล้ว

      @@gamoholic7653 I program in c++, I don't think it's legal, everytime I use an integer to initialize size of array, it flashes illegal initialization error, size cannot be vector value

    • @123akash121
      @123akash121 3 ปีที่แล้ว +1

      it wasnt orignally a part of c, its called variable length array (VLA), VLA has been there since C99 and has been optional since C11, however big compilers like clang or gcc will never remove it probably

  • @jenilsoni3527
    @jenilsoni3527 5 ปีที่แล้ว +292

    He malloc,
    He calloc,
    but most importantly...
    He realloc to 0.

  • @poggly
    @poggly 6 ปีที่แล้ว +1

    this is a great video- i was hesitant at first because the videos on this topic were long but it's very concise and explains everything with specific examples

  • @NisargDalvi
    @NisargDalvi 9 ปีที่แล้ว +1

    I've been searching all throughout for a good video on malloc, and I have to say.
    This is the BEST tutorial that I have found.
    Excellent tutorial.
    Thank you very much

  • @sachinjamdar3923
    @sachinjamdar3923 6 ปีที่แล้ว +1

    sir thank you so much for this video.before i watch this video i had fear of pointer now i am feel good in pointer .your teaching technique is too good .

  • @RishabhJain-iz5xk
    @RishabhJain-iz5xk 4 ปีที่แล้ว +2

    Bruhh you explained this concept like a pro...i almost cried:D

  • @NO-1-U-NO
    @NO-1-U-NO 5 ปีที่แล้ว +2

    🙂👍 You sir have helped a lot of Students, including me, better Understand the Dynamic Memory Allocation. Thank You!

  • @ozzyfromspace
    @ozzyfromspace 5 ปีที่แล้ว +2

    To be clear, realloc() is a god-tier function 😂. Awesome explanation, you're A1, brother!

  • @urieltzuberi9885
    @urieltzuberi9885 3 ปีที่แล้ว +1

    Thanks man, that actually showed me what malloc is. I had so much trouble and you made it easy, thank you so much

  • @ankajkumar595
    @ankajkumar595 5 ปีที่แล้ว +1

    Brilliant sir!
    After watching this video I found myself comfortable with dynamic memory allocation......

  • @tannermiller5412
    @tannermiller5412 6 ปีที่แล้ว

    I am about 5 years late to the party but this video was amazing at explaining these dynamic memory allocation functions, much much better than my prof ever could. Thank you!!

  • @atulsaswat1153
    @atulsaswat1153 5 ปีที่แล้ว +14

    10:00 However, the value of an array can be a variable. However, I must say MCS is a must-visit source to understand pointers.

    • @amritasaha2793
      @amritasaha2793 4 ปีที่แล้ว +4

      variable size of array is allowed in C after C99 onward.

    • @vishwaja1523
      @vishwaja1523 4 ปีที่แล้ว +1

      @@amritasaha2793 u mean that we can do a[n] declaration in new version of c ?

    • @jaykumargupta7307
      @jaykumargupta7307 4 ปีที่แล้ว

      @@vishwaja1523 in c++ we can definitely do

    • @PraddyumnShukla
      @PraddyumnShukla 4 ปีที่แล้ว +2

      @@vishwaja1523 Yes we can. After taking 'n' as input, we can create an array of size 'n' in c !!

    • @okaybossiamonyoutubeakkskd
      @okaybossiamonyoutubeakkskd 2 ปีที่แล้ว

      @@vishwaja1523 #include
      int main()
      {
      int n;
      scanf("%d", &n);
      char arr[n];
      scanf("%c", &arr[n - 2]); // it was fine uptill this one.
      scanf("%c", &arr[n - 1]); // here the size gets too big for run time operation
      printf("%c
      ", arr[n - 2]);
      printf("%c", arr[n - 1]);
      return 0;
      }
      /* Deciding an array size at runtime is possible in modern C (>= C99)
      and code like the below is fine.
      One obvious drawback of VLAs is that if s is quite big and the allocation of
      a could fail. Worse, there's no way to check if the allocation has failed
      and you'll run into runtime errors (e.g., segfault).
      It's essentially undefined behaviour */
      /*
      #include
      int main() {

      int n;
      scanf("%d",&n);
      int arr[n];

      scanf("%d", &arr[n-2]);
      scanf("%d", &arr[n-1]); //both of these works being smaller in size.


      printf("%d
      ",arr[n-2]);
      printf("%d",arr[n-1]);


      return 0;
      }
      */
      YES WE CAN

  • @Itskfx
    @Itskfx 2 ปีที่แล้ว +1

    I was having a lot of difficulty in understanding DMA but this cleared it up. Thanks!

  • @LifeWithGod99
    @LifeWithGod99 10 ปีที่แล้ว +14

    Sir, thank you for your kind explanation, you have some really good didactic skills, congratulations!

  • @MitchellD249
    @MitchellD249 10 ปีที่แล้ว +4

    Fantastic video. I would add one thing to the explanation of why malloc(sizeof(int)) should be used instead of malloc(4); it makes the code a lot more readable. Somebody else reading the code will see the number 4 and potentially have no idea why it is there, but when they see sizeof(int) they know exactly what it represents. No magic numbers!

    • @bashehu
      @bashehu 2 ปีที่แล้ว +1

      The size of int is not 4bytes for all machines

  • @Humberd01
    @Humberd01 11 ปีที่แล้ว

    Very nicely explained, I understood everything although I am not native english speaker. You got my like.

  • @jejwjs8700
    @jejwjs8700 2 ปีที่แล้ว

    A very helpfull video, you teach better than all my professors.

  • @riyadunnabi
    @riyadunnabi 9 หลายเดือนก่อน

    this is the only video that made me understand dynamic memory allocation in c

  • @andreamarchisio9608
    @andreamarchisio9608 8 ปีที่แล้ว +1

    Thanks man! Most of ICT teachers should learn to explain as you do

  • @efodela4u
    @efodela4u 11 ปีที่แล้ว

    Awesome video, you explained this to me like no one would ever have.. thanks
    .

  • @DHRUVNARAYANSINGH
    @DHRUVNARAYANSINGH 9 ปีที่แล้ว +1

    Sir ,thank you for providing best programming video for free !

  • @shakiulanam6569
    @shakiulanam6569 7 ปีที่แล้ว +1

    i have lost my word to explain the quality of this video series , carry on sir best wish for you for such kind of dedication.

    • @yatinbahl6240
      @yatinbahl6240 3 ปีที่แล้ว

      He is no more brother

    • @shakiulanam6569
      @shakiulanam6569 3 ปีที่แล้ว

      @@yatinbahl6240 ooo my god !! how?

    • @yatinbahl6240
      @yatinbahl6240 3 ปีที่แล้ว

      @@shakiulanam6569 He died in a car accident. Luckily his wife survived in that accident.

    • @yatinbahl6240
      @yatinbahl6240 3 ปีที่แล้ว

      @@shakiulanam6569You can go through this link to know what happened actually.
      www.google.com/url?sa=t&source=web&rct=j&url=www.freecodecamp.org/news/mycodeschool-youtube-channel-history/amp/&ved=2ahUKEwi169TOwrXwAhWbIbcAHTa3A2oQFjACegQIFxAC&usg=AOvVaw1qjV_46-q46sfTrJpe96jt&cf=1

  • @winsonlcc1562
    @winsonlcc1562 2 ปีที่แล้ว

    This is great video, clear my doubt! Superb explanation and sample code.
    Greetings from Malaysia

  • @GoodwillMonyai
    @GoodwillMonyai ปีที่แล้ว +4

    🎯 Key Takeaways for quick navigation:
    00:24 🛠️ malloc, calloc, realloc, and free are key functions for dynamic memory allocation in C.
    01:23 📏 malloc allocates memory based on the specified size, returning a void pointer.
    02:43 📝 Sizeof and typecasting ensure proper allocation for specific data types.
    05:00 🚀 Use typecasting to convert void pointers to specific data types for manipulation.
    06:43 ➡️ Dynamic memory manipulation is done through pointers, incrementing for array traversal.
    07:09 📊 Calloc initializes allocated memory with zero values, unlike malloc.
    08:32 🔄 Realloc modifies memory block size, potentially copying and extending existing data.
    09:27 📦 Dynamically allocate memory for arrays, prompt user input, and store data.
    10:52 📋 Typecast and initialize memory when using calloc for dynamic arrays.
    12:14 ❗️ Use free to deallocate dynamically allocated memory when it's no longer needed.
    14:34 ↔️ Realloc resizes memory blocks, possibly extending or reducing existing blocks.
    17:13 🔀 Realloc can serve as a substitute for malloc and free, offering flexibility.
    Made with HARPA AI

  • @senaustun4380
    @senaustun4380 2 ปีที่แล้ว

    even videos with my native language couldn't explain it this well thank you :D

  • @LavanshuSeth
    @LavanshuSeth 8 ปีที่แล้ว

    I had that "not so obvious question" for a long time. Even my teacher had no clue how that happened when I asked her. Well, now I know it. Thanks a lot. :)

  • @MujtabaNowshad
    @MujtabaNowshad 11 ปีที่แล้ว

    best Malloc tutorial on TH-cam

  • @gpanag93
    @gpanag93 11 ปีที่แล้ว +9

    You should become a teacher if you aren't already.. great and detailed tutorial for difficult and demanding students like myself..

    • @mycodeschool
      @mycodeschool  11 ปีที่แล้ว +8

      Hi George Pan -
      I am not a professional teacher, but yes I love to teach.

  • @evadethomas8223
    @evadethomas8223 ปีที่แล้ว

    Bro I appreciate you so much. Saved me for this midterm I'm about to take tomorrow.

  • @omondioliech
    @omondioliech ปีที่แล้ว

    I love this, the topic is widely explained. Thank you very much Sir.

  • @TrevDevSwag
    @TrevDevSwag 10 ปีที่แล้ว +3

    Thank you bro! This video help me a lot! I didn't understand nothing from my C professor. :)
    Respect!

  • @alexlapena
    @alexlapena 8 ปีที่แล้ว +33

    I love this guy.

  • @BarakaAndrew
    @BarakaAndrew 10 ปีที่แล้ว

    This guy is awesome...!! Finally i understood this n can use it well in my assignments... Thanks alot!!!
    My professor is so boring!!

  • @sillystupidpastime
    @sillystupidpastime 7 ปีที่แล้ว +1

    2:15 up to 7:00 MALLOC() for those pressed for time &
    9:18 compiler input with real code

  • @phicsvinci
    @phicsvinci ปีที่แล้ว

    Wow I thought malloc realloc and calloc would take my whole day but 17 mins and I did
    Thanks man one❤

  • @abhishektiwari8514
    @abhishektiwari8514 9 ปีที่แล้ว +1

    we can allocate stack data in compile time now !
    It used to give errors in the older versions of C (or C++).
    meaning,
    int n;
    scanf("%d",&n);
    int A[n];
    doesn't give any error (up-to some limits on n.
    For my PC the range is 100,000 approx. It may be the stack size available in the Memory,I am not sure.)

  • @vivekmuralidharan4913
    @vivekmuralidharan4913 10 ปีที่แล้ว

    Wonderful explanations!!!Dynamic memory allocation made easy by you!! Thanks a lot!!

  • @AndrewAcostaYT
    @AndrewAcostaYT 8 ปีที่แล้ว

    First of all, thank you so much for making this video, you have no idea how much it helped. But I do want to say that when I write code as: int A[n] it stills compiles with no errors, and when I run the program it prints the same result; I am using GNU Make 4.2. The only thing is now I can not free the memory so I like allocating it because it gives a pointer so I can free it later.

  • @vishalmaheshwari5088
    @vishalmaheshwari5088 8 ปีที่แล้ว +1

    Great explanation!! You really make things a cakewalk. Thanks!!

  • @dipanshu2310
    @dipanshu2310 5 ปีที่แล้ว

    excellent explanation you helped many of us. Thanks from students at IIT Mandi.

  • @lucasf.v.n.4197
    @lucasf.v.n.4197 3 ปีที่แล้ว

    The example at minute 10 is just what I was looking for, thx

  • @koyavasudhalakshmi2073
    @koyavasudhalakshmi2073 3 ปีที่แล้ว +1

    Awesome explanation sir!!!I understood very well 🙏🙏🙏🙏

  • @Yasory
    @Yasory 9 ปีที่แล้ว

    I finally know how to dynamically allocate memory...And two nights before my exam! thank you so much!!

  • @PratikShende91
    @PratikShende91 9 ปีที่แล้ว

    thanks for sharing such quality videos sir....your teaching skills are perfect...now my concepts are more clear....

  • @karinafran9463
    @karinafran9463 7 ปีที่แล้ว

    Thank you for making this video! It honestly helped me so much. You're a great teacher!

  • @sksatheeshec
    @sksatheeshec 6 ปีที่แล้ว

    Superb explanation bro. Thanks lot... Its was very clear enough to understand a newbie also.....

  • @samarpanrai5924
    @samarpanrai5924 2 ปีที่แล้ว

    Finally after 2 years I can say that I know about dynamic memory allocation.

  • @zzzweasel
    @zzzweasel 5 ปีที่แล้ว +3

    this was extremely clear and helpful, thank you!

  • @alexiaandreea229
    @alexiaandreea229 4 ปีที่แล้ว

    Thank you so much!
    Student from Romania

  • @MultiSapMan
    @MultiSapMan 10 ปีที่แล้ว +1

    Amazing video. Outstanding explanation.
    Thanks a whole bunch mate.

  • @ThereYouGoFromHere
    @ThereYouGoFromHere 9 ปีที่แล้ว +16

    sir i have a question.
    when we use free(A), A is only a pointer to the base address of the memory allocated. How does free know exactly how many bytes of memory to be freed? that is when to stop the deallocation?

    • @mohdadil2301
      @mohdadil2301 9 ปีที่แล้ว +19

      Ayindrila Bhattacharyya
      Most implementations of C memory allocation functions will store accounting information for each block, either inline or separately.One typical way (inline) is to actually allocate both a header and the memory you asked for, padded out to some minimum size. So for example, if you asked for 20 bytes, the system may allocate a 48-byte block:16-byte header containing size, special marker, checksum, pointers to next/previous block and so on.32 bytes data area (your 20 bytes padded out to a multiple of 16).The address then given to you is the address of the data area. Then, when you free the block, freewill simply take the address you give it and, assuming you haven't stuffed up that address or the memory around it, check the accounting information immediately before it.Keep in mind the size of the header and the padding are totally implementation defined (actually, the entire thing is implementation-defined (a) but the inline-accounting-info option is a common one).The checksums and special markers that exist in the accounting information are often the cause of errors like "Memory arena corrupted" if you overwrite them. The padding (to make allocation more efficient) is why you can sometimes write a little bit beyond the end of your requested space without causing problems (still, don't do that, it's undefined behaviour and, just because it works sometimes, doesn't mean it's okay to do it).(a) I've written implementations of malloc in embedded systems where you got 128 bytes no matter what you asked for (that was the size of the largest structure in the system) and a simple non-inline bit-mask was used to decide whether a 128-byte chunk was allocated or not.Others I've developed had different pools for 16-byte chunks, 64-bytes chunks, 256-byte chunks and 1K chunks, again using a bitmask to reduce the overhead of the accounting information and to increase the speed of malloc and free (no need to coalesce adjacent free blocks), particularly important in the environment we were working in.

  • @FTL3RR
    @FTL3RR 5 ปีที่แล้ว +1

    OMG.. this is amazing! Why can't my professor explain like him???

  • @zerocool0510
    @zerocool0510 11 ปีที่แล้ว

    You saved my life with this video

  • @pfkong6917
    @pfkong6917 8 ปีที่แล้ว +1

    what an amazing video you made ,it really helped me a lot ! you do a great job !

  • @mycodeschool
    @mycodeschool  11 ปีที่แล้ว +2

    Thanks Daniel !!

  • @jatingupta9769
    @jatingupta9769 7 ปีที่แล้ว +1

    best tutorial on internet

  • @shiftgrifts
    @shiftgrifts 10 ปีที่แล้ว +1

    Really helpful and concise! Thank you very much!

  • @AryanKumar-wy1zk
    @AryanKumar-wy1zk 3 ปีที่แล้ว +1

    It was uploaded on my birthday :)

  • @phicsvinci
    @phicsvinci ปีที่แล้ว

    My code school is so awesome ❤❤

  • @אלקנהגמליאל
    @אלקנהגמליאל 6 ปีที่แล้ว

    this video is great! your explanation is so clear and helped me a lot ! tnx!!

  • @annaaleykina6061
    @annaaleykina6061 10 ปีที่แล้ว

    Thank you so much for the great explanation, sir. Best video on this subject that I found. You should become a teacher :)

  • @rajeshbiswas755
    @rajeshbiswas755 6 ปีที่แล้ว

    this video is seriously very helpful.thank you very much

  • @AliMalik-uw1rk
    @AliMalik-uw1rk 4 ปีที่แล้ว

    wow!!! man great explanation.... I wish my university professor could explain like the way u did.....

  • @boisbois2947
    @boisbois2947 4 ปีที่แล้ว

    You literally saved my life!

  • @jvsnyc
    @jvsnyc 2 ปีที่แล้ว

    At ~16:30, while in the old days we thought it was okay to do a realloc( ptr, 0 ) as a free(), this is very much deprecated now. It is flat-out undefined behavior in C23 now. Other than that small detail, a great video.

  • @QuanNguyen-og6pq
    @QuanNguyen-og6pq 4 ปีที่แล้ว

    The man, the myth, the legend!

  • @noordamnick
    @noordamnick 5 ปีที่แล้ว +1

    great video, I finally understand these concepts.

  • @anastasiadunbar5246
    @anastasiadunbar5246 6 ปีที่แล้ว

    If you're doing something like:
    unsigned char*list=(unsigned char*)calloc(size,sizeof(unsigned char));
    You can shorten it to (without type casting, not all compilers allow this):
    unsigned char*list=calloc(size,1);
    Because sizeof(char) is always 1.

  • @parthmalkan8366
    @parthmalkan8366 10 ปีที่แล้ว +1

    I am really thankful to you for this wonderful lecture series. I wanted to understand connection between heap and hugepages on linux. How to find out what's the heap size of our system on Linux and how to increase the heap size.
    Thanks