Track MEMORY ALLOCATIONS the Easy Way in C++

The first 500 people who click the link will get 2 free months of Skillshare Premium: skl.sh/thechernoproject5
Patreon ► / thecherno
Instagram ► / thecherno
Twitter ► / thecherno
Discord ► thecherno.com/discord
Series Playlist ► thecherno.com/cpp
This video was sponsored by Skillshare

Пікірлер: 391

  • @supersquare
    @supersquare4 жыл бұрын

    I'm not even joking, you're LITERALLY posting videos on problems exactly when I have them. First with singletons, then small string optimizations, and now this lmao Thank you so much for the help!

  • @Saje3l

    @Saje3l

    4 жыл бұрын

    same here

  • @danielkrajnik3817

    @danielkrajnik3817

    3 жыл бұрын

    survivorship bias, even though I love cherno, this is just a survivorship bias

  • @fallenflame8678

    @fallenflame8678

    Жыл бұрын

    @@danielkrajnik3817 and c++ programmers always have problems with memory

  • @pureflame8867
    @pureflame88674 жыл бұрын

    Q&A : Got any plans or words to say about unit testing in c++?

  • @wz5445
    @wz54453 жыл бұрын

    Cherno, thank you so much for this series, it helps me so much with understanding c++, this is exactly what I need. The majority of other channels only provide examples without really explaining what and why. Honestly man, respect. And I'm wondering if you could do some videos on design patterns and UML? I was running into it in school but didn't find the lectures very helpful lol

  • @hpsmash77
    @hpsmash773 жыл бұрын

    "hello world is not gonna use that much memory" lets just hope that the internet doesn't take this as a challenge

  • @kaihaolin1838
    @kaihaolin18384 жыл бұрын

    wow, you're still updating the cpp series in 2020.Recently I have comtinued to watch 40 videos on this series. it is awesome ,very nice!

  • @Nick-lx4fo

    @Nick-lx4fo

    3 жыл бұрын

    This series is so awesome I've watched every video up to this one in a few days

  • @andreistefanie
    @andreistefanie4 жыл бұрын

    Q&A: How experienced (as programmers) do you think most of your viewers are?

  • @foomoo1088
    @foomoo1088 Жыл бұрын

    Nice and straight forward for simple scenarios. Be aware there are a few flavors of new and delete to override (arrays, etc) and also any libraries you link to may bypass your overloaded versions depending on how you build and link them

  • @sireeshaputcha
    @sireeshaputcha4 жыл бұрын

    Q&A: Firstly, thanks a lot for making these videos. You literally helped me get through my entire computer graphics course. I'm trying to become a game developer and have been following your videos on C++ and gamedev for quite a while now. What do you think can help/did help you become so good at game development? How challenging is it to work for any AAA game company? Thanks a ton!

  • @PedroOliveira-sl6nw
    @PedroOliveira-sl6nw4 жыл бұрын

    Great work! Regarding the Q&A, it's not a question but I'd love to hear about (1) Vectorization and (2) Allocators [freelist, etc..].

  • @401281
    @4012814 жыл бұрын

    I always learn something new when I watch your videos, thank you for posting these amazing resources.

  • @gj9ekdjekray
    @gj9ekdjekray4 жыл бұрын

    Thanks a lot for making these videos!! Q&A: Looking forward to a compiling series~

  • @PrinceGupta-jo8lo
    @PrinceGupta-jo8lo4 жыл бұрын

    Thanks a lot, Cherno, I was struggling a lot understanding value references and use of std::move in the codebase of MLPack, but the introduction and hint of how move semantics work really helped a lot.

  • @poolmorosanacona1930
    @poolmorosanacona19304 жыл бұрын

    Thank you! You've helped me a lot, your videos are really good, It's very easy to understand what you explain :D

  • @andre_4046
    @andre_40462 жыл бұрын

    This actually helped me big time. Big thanks Cherno!

  • @RakeshSolanki1
    @RakeshSolanki1 Жыл бұрын

    You showed it the best way. Most of the time it's easy to understand our own code than other's tool and how to use those tools. I like your grounded (stick to the basic) approach.

  • @atrumluminarium
    @atrumluminarium4 жыл бұрын

    Q&A: Do you have any plans to cover some "tips and tricks" with regards to compute in C++? For example parallel calculations in linear algebra with openmp/opencl/cuda etc

  • @shaebazz1
    @shaebazz14 жыл бұрын

    Q&A: Will you be doing a series on Design Patterns (like Singletons)? What design patterns are used in game engines you work on?

  • @isaaclacoba4458
    @isaaclacoba44584 жыл бұрын

    Nice explanation. I like the way you use. encapsulation and Design patterns to create your own examples. Keep the good work!

  • @playerplayer1114
    @playerplayer11144 жыл бұрын

    Thank you so much Yan! You helped me alot to learn C++ !

  • @brunooliveirasoares7489
    @brunooliveirasoares74894 жыл бұрын

    Great video, as always! You could make a live with the Q&A... that would be interesting! Q&A: Which literature do you recommend regarding the very bases of computer science, like process, threads, algorithms... ?

  • @chicoern
    @chicoern Жыл бұрын

    F@ck, I'm new to C++ and lost count of how many times you tough me more C++ than any other forum, book, page, etc.... Awesome content, love it!

  • @parthlodhia5552
    @parthlodhia55524 жыл бұрын

    Nice bro, keep on Really help full.

  • @zuhail339
    @zuhail3393 жыл бұрын

    Tysm for being so consistent with c++ .

  • @dojo2029
    @dojo2029 Жыл бұрын

    Great, thank you for sharing your knowledge and experience!

  • @newoap
    @newoap4 жыл бұрын

    Great stuff as always. Surprised you haven't done move semantics and perfect forwarding so that's my request.

  • @perfectionbox
    @perfectionbox3 жыл бұрын

    A nice feature of POV-Ray's memory allocator is that blocks can be tagged with a string, making it easy to identify them. Breakpointing operator new or malloc is difficult when there's tons of allocations occurring.

  • @alitabrizi9811
    @alitabrizi98114 жыл бұрын

    Hey. always loved your videos. Any plans on doing some videos on memory leaks and tools for monitoring them???

  • @nikorasub1410
    @nikorasub14104 жыл бұрын

    Thanks for you great tutorial , I think your tutorial in more focus on "advanced" C++ topic is a great idea.. when I make interview for jobs, they mainly focus on memory part and not "how do you write this" etc etc Q&A : Do you plan to make video about video game C++ technique use in industry (like managing memory for actor with cache, or display a tons of object by example) ? Please continue your great works !

  • @tonholis
    @tonholis3 жыл бұрын

    That helps a lot! Thanks. Is there any video about best practices dealing with large amounts of data (like images)?

  • @davidrees1452
    @davidrees14524 жыл бұрын

    Q&A: Do you plan on continuing the expansion of the C++ playlist with more "beginner" tutorials? Such as creating videos about subjects you would possibly cover in a later videos. I am interested in your take on lvalues & rvalues, design patterns, best practices for beginners, how to use threads in your program, etc.

  • @QckSGaming
    @QckSGaming4 жыл бұрын

    Excellent video as always! Keep on doing this stuff, I couldn't get through uni without you lmao Question arises though: How does it effect performance (especially game engine with many allocations) if you write a bit more code in the overloads? Should you create a separate reference counter class in that case that would do the things for you, like call new etc. without actually overloading the standard functionality?

  • @felipecarlin8540
    @felipecarlin85404 жыл бұрын

    More of a personal question, when did your interest in game engine development start? I think this is intriguing, because my interest in it started because of your channel. Thanks for the amazing content!

  • @simeonlazarov5643
    @simeonlazarov56434 жыл бұрын

    Q&A: My idea is to show off anything that you use in visual studio (mainly). Maybe 2-3 video and by anything I mean keybinds, tools and so on, everything that help us to write fast and good code. Thank you for the best C++ tutorials on the internet, they are as simple as possible and show anything you need to know just to start writing code.

  • @aquavitale3551
    @aquavitale35514 жыл бұрын

    Thanks for doing great series! How much time do you spend on working on a typical video, at average?

  • @soulimanemammar2909
    @soulimanemammar29094 жыл бұрын

    It's always possible to write a memory Allocator that handle and optimize most use cases and fallback to new/delete for extreme cases...most std library function are Allocator friendly

  • @iamagenius2646
    @iamagenius26464 жыл бұрын

    Q&A : can you make a video on client side prediction ? And networking in general

  • @konstantinrebrov675
    @konstantinrebrov6754 жыл бұрын

    Q&A: What are your opinions about programming languages like Rust and Go vs C++? Can you make some videos about low level system programming in Windows? I know the Linux system calls, but I want to transition to Windows. Have you ever used Microsoft's Managed C++, and can you make a video about it? What are your favorite APIs for C and C++? What should a "good programmer" know about C and C++ in order to get a job? How many hours each week do you devote to researching about programming, and how do you keep track of all the other tasks you have to do?

  • @matthewpeterson5159
    @matthewpeterson51594 жыл бұрын

    oml that keyboard tho :P glad to see you're still uploading after what feels like years lol

  • @aliberro
    @aliberro4 жыл бұрын

    At 0:56 you won't write an app that uses alot of memory Google Chrome Devs: Ohh challenge accepted!

  • @user-cc8kb
    @user-cc8kb4 жыл бұрын

    super useful! thank you

  • @mateuszbahyrycz7003
    @mateuszbahyrycz70034 жыл бұрын

    Great video Cherno !

  • @vijaypatil873
    @vijaypatil8734 жыл бұрын

    Q&A : Do you plan on starting your own startup in near future?

  • @bpeachey1475
    @bpeachey14753 жыл бұрын

    Hi, great videos BTW! What's the hot keys for moving and entire line of code up or down???

  • @seditt5146
    @seditt51464 жыл бұрын

    For a Q&A I always wanted to know if your Game Engines, Sparky and Hazel are indicative of the sort of Engines you worked on in your professional work. Did they use far more complex and optimized code or does your work reflect what you seen in your time in the industry?

  • @glennstormdesign
    @glennstormdesign3 жыл бұрын

    LOL, _of course_ you continued to show me what I needed, even whilst I dropped off the earth. Thx; I’ll be able to pick things right back up. :)

  • @user-tz5bz4cz9q
    @user-tz5bz4cz9q3 жыл бұрын

    Thank's the Cherno! Cool video tutorial!

  • @littleclouds1
    @littleclouds14 жыл бұрын

    Q&A: It would be nice if you could give an example of when to use Batch Rendering and Instanced Rendering with the pros and cons. PS: Really looking forward to seeing more of the new office :)

  • @rockwellldreamn5843
    @rockwellldreamn58433 жыл бұрын

    Very cool video! Thank you!

  • @brunodelafontaine1637
    @brunodelafontaine16374 жыл бұрын

    Your videos are amazing man. Great explanation. Any book recommendations for c/c++ for embedded software? Also have you ever done embedded software?

  • @harrirahikainen4196

    @harrirahikainen4196

    4 жыл бұрын

    I would also appreciate more performance related stuff as I would like to transition to C++ from C in my company. Although game development is closer to embedded than most fields you see represented in KZread for example

  • @XxxGuitarMadnessxxX
    @XxxGuitarMadnessxxX2 жыл бұрын

    I'm quite happy to have found this video in google search lol I'm messing around with color tagging in a current project and by using your method here, I noticed that one implementation of a certain function allocates almost 40 times less (a bunch of small allocations with mapping and strings) going from 1936 bytes to 56 bytes compared to the original function I wrote by instead using constexpr const char* for color codes , using string_views, and eliminating the table lookups in the form of the mapping that was taking place. Seriously, thank you for this video! It's useful tips and tricks like these that make me excited to keep on learning =D EDIT: Just watched your small string optimization vid after this one and realized i could just use const std::string instead of constexpr const char* (probs should've been using const char* const instead of constexpr const char* anyways if i'm being honest.. woops lol). I'll say it again until I'm blue in the face - thank you for these videos!!

  • @mang0men1
    @mang0men14 жыл бұрын

    Can you recommend a book or some steps on how to optimize an algorithm in general. What is your general aproach ?

  • @quaintbear
    @quaintbear4 жыл бұрын

    Спасибо за видосы! Узнаю больше чем от препдов.

  • @psyience3213
    @psyience321310 ай бұрын

    That’s pretty cool. I wrote my own smart pointer class that handles memory allocation deallocation, I should add something to it that tracks total memory usage

  • @Ghasakable
    @GhasakableАй бұрын

    The implementation of the de-allocation is based on which complier you are using, for clang++ you can pass the flag -fsized-deallocation as it is not implemented yet for GNU GCC g++ its supported by default

  • @arielspalter7425
    @arielspalter74254 жыл бұрын

    Amazingly useful.

  • @Ethan-dm2yz
    @Ethan-dm2yz4 жыл бұрын

    beg you to make such more videos on "working memory and the C++ programming syntax interrelation". It really makes "sense" for writing absolute and optimized programm. PLEASE.PLEASE.PLEASE......

  • @svenbtb
    @svenbtb10 ай бұрын

    this is so simple but really smart, I'll totally have to remember this

  • @FatherOfTheParty
    @FatherOfTheParty4 жыл бұрын

    Very nice treatment of interposition from the language level.

  • @Yupppi
    @Yupppi5 ай бұрын

    This felt super useful. I learned that just a very simple program of 230 lines, that takes a couple of decimal measurements of a part and calculates a standard deviation based quality key numbers and prints them out wouldn't have fit in like a manufacturing industry machine memory a decade or couple ago. Heck, almost 600 kb for that? To calculate and print out 3 numbers from 8 numbers. We live in the age of luxury. Honestly most automation logic codes inside PLC units are smaller I'm pretty sure.

  • @EmbeddedSorcery
    @EmbeddedSorcery4 жыл бұрын

    This might really be useful in an embedded environment.... however, how might I try it if we already override new for class constructors in order to force static allocation of those classes? (like a Hardware class that there only ever needs to be one of)

  • @gamingtech276
    @gamingtech2764 жыл бұрын

    What's your stand when it comes to mixing underscore and camel case?

  • @angucbac2655
    @angucbac26554 жыл бұрын

    Could you make a tutorial about callback in c++? Thank for your sharing

  • @nfrancisj2122
    @nfrancisj21224 жыл бұрын

    A request! if you're taking requests. It would be super awesome if you could do a Math : Games Edition series...or vlog. Just a talk about what kinda math is helpful/required for engine development. Thx!

  • @SuperCiao000
    @SuperCiao000 Жыл бұрын

    thank you so much, this is a really useful trick. You are the best

  • @rafalmichalski4893
    @rafalmichalski48934 жыл бұрын

    Hello Cherno. Does delete operator taking size params work with built-in types like int ? If not how to count freeing it from heap ?

  • @uqxtimbl
    @uqxtimbl3 жыл бұрын

    The delete operator with size parameter is never called for me, when using gcc or clang. Neither in debug nor release optimization. And it seems it is basically not really supported officialy, the compiler just chooses the non-size-parameter version anytime it wants to.

  • @massimilianoalessio2953
    @massimilianoalessio295324 күн бұрын

    Hi Cherno! Thanks for your wonderfull videos: them helps me a lot! If i can i've got a questions: i've try such example with an array. Once call delete[] i cannot hit the delete overload function....Tried with overloading delete[] too without any success. The point is, i don't understand why for array ptr the delete is not called! Thanks again for your unbelievable job!

  • @muhammadtaimourafzal5285
    @muhammadtaimourafzal52853 жыл бұрын

    that was amazing

  • @neilbroomfield3080
    @neilbroomfield30803 жыл бұрын

    Are there any issues with multi-threading and not using atomic variables/functions to manipulated your metrics?

  • @juliancruz1927
    @juliancruz19274 жыл бұрын

    200k followers because you're a great teacher. Can you do some advance videos about ComputeShaders and also some about debugging CPU and GPU series? Pls!!! :)

  • @tonghaoyuan
    @tonghaoyuan3 жыл бұрын

    If you use clang you may want to override both void operator delete(void* ptr) noexcept{} and void operator delete(void* ptr, size_t size) noexcept{}

  • @zhuping1506
    @zhuping15064 жыл бұрын

    Would you please make a video about multi-threading in c++?

  • @tcholly
    @tcholly3 жыл бұрын

    you can explain all in a good way, you have a mechanical keyboard, you only need a static sound from the microphone and an indian accent and you're perfect

  • @rufusli7056
    @rufusli70564 жыл бұрын

    You can also use compilers to help you by compiling C++ code with address sanitizer and leak sanitizer flags.

  • @colinmaharaj
    @colinmaharaj4 жыл бұрын

    I still use new/delete and new[]/delete[]. Many years ago I wrote a new/delete scanner to find new's' and look for the corresponding delete's'. If it could not find the delete the app would give an error.

  • @Xxp0r
    @Xxp0r4 жыл бұрын

    When will you do a C++ Video on Exception handling, and why you don't use it?

  • @ekremdincel1505

    @ekremdincel1505

    4 жыл бұрын

    @Ricardo Santos lol "goto is harmful" cant be a reason for this. Dont use loops if you dont want "goto"s in your compiled program. Exception handling is useful, just do it right.

  • @BOTHLine
    @BOTHLine3 жыл бұрын

    2 short questions: Are there some situations in std where the "new" keyword is not used, but malloc() is called directly? Such a case you wouldn't detect by overriding the new operator? When freeing the memory and only passing a void*, how does the system know how much memory to free?

  • @K9Megahertz
    @K9Megahertz Жыл бұрын

    Paul Nettle wrote a memory manager many years ago that overwrote new/delete/malloc/free/etc... and tracked all the memory allocations and printed out a nice report of unfree'd memory among other stats at the end of program termination. I think you can still find it online. It was a header file you had to include with every sourcefile you wanted to track. It worked really well, at least for single threaded applications. It didn't play nice with multithreaded code but maybe that could be fixed. I tried many years ago but my Kung Fu wasn't all that good at the time. I might be able to make better sense of it now. Ehh, maybe something I'll revisit at some point.

  • @alextiga8166
    @alextiga81664 жыл бұрын

    Would be nice to mention that this example wouldn't call the constructor like the original "new" operator(same applies to destructor call with the "delete" operator) so the beginners won't wonder why doesn't their code work after they overwrite the "new" and "delete" operators.

  • @jonathancerbaro713
    @jonathancerbaro713 Жыл бұрын

    Ok, that trick was amazing

  • @popcultureprogrammer2171
    @popcultureprogrammer2171 Жыл бұрын

    wooow this is pretty freaking cool

  • @DrGreenGiant
    @DrGreenGiant4 жыл бұрын

    Q&A please can you explain virtual inheritance?

  • @dominicrodriguez7413
    @dominicrodriguez74134 жыл бұрын

    It would be great to hear about how you learned advanced level programming - not how you started but how you developed the skills to work on highly technical projects like game engines

  • @leZigoute

    @leZigoute

    4 жыл бұрын

    Being curious is the answer. Incremental learning. Don't try to learn everything at once but build your skill one step at a time.

  • @masheroz
    @masheroz2 жыл бұрын

    How does just adding a second parameter to your own delete function grab the size?

  • @Chris-xn9zm
    @Chris-xn9zm4 жыл бұрын

    Q&A: Where/how do you get information regarding topics such as this one?

  • @eddyecko94

    @eddyecko94

    4 жыл бұрын

    Chris I think working with other great developers excite your curiosity too, there are some things you wouldn’t even bother looking into unless your livelihood depends on it.

  • @techdiver6074
    @techdiver60742 жыл бұрын

    I'm writing audio software. DAWs are unpredictable. This is going to come in handy immediately!

  • @DoubleCoolOp
    @DoubleCoolOp3 жыл бұрын

    How to overload delete[] for arrays to show memory freed ?

  • @edugar88
    @edugar883 жыл бұрын

    Really nice content

  • @syeduthman
    @syeduthman3 жыл бұрын

    Does the sound of keyboard being record during you demo the coding? Is that your normal typing speed? or it just video post edit process.

  • @ahmadshbat8363
    @ahmadshbat83632 жыл бұрын

    Dude You deserve to lead a company!

  • @2wheels2
    @2wheels24 жыл бұрын

    what companies or job types would require c++, a job type being desktop programmer or database management.

  • @mrbisht8638
    @mrbisht86384 жыл бұрын

    A video on ways to detect or debug memory leaks will be really really beneficial ?

  • @tameryldrgan552
    @tameryldrgan552 Жыл бұрын

    Question: Using new operator automatically triger consruction method of class. You override it and use malloc inside it. Does it run constructor automatically and how?

  • @rupin4004
    @rupin40044 жыл бұрын

    Q&A : hey. So I've learnt c++ for 2 yrs in high school but, but but it was on 'turbo c' compiler which is like very much isolated from rest or the galaxy and even though I am fairly intermediate level programer in turbo c but I really can't understand anything done outside this compiler ( ican but you know what I mean??) , PLEASE make a video on how to get out of that compiler and what actually I can do with other ones which turbo c can't do🙂

  • @breeze2440

    @breeze2440

    4 жыл бұрын

    Bro i was used to turbo c too cuz that's the only thing on I got taught in school.. but I have recently installed vs and started cherno series,it's too easy... It's been week and now I am out of that turbo shit and the environment in vs feels much more comfortable ♥️

  • @rupin4004

    @rupin4004

    4 жыл бұрын

    @@breeze2440 thankyou for your response, and yes I have also installed vs and codeblocks and I'm now practiceing on them .😊

  • @shighilpothery7012
    @shighilpothery70124 жыл бұрын

    Please cover the upcoming features in c++20.

  • @mrbisht8638
    @mrbisht86384 жыл бұрын

    Boost library or any other libraries used most in the market ?

  • @dehufters
    @dehufters4 жыл бұрын

    is there a version of this vid without the screaming background noise (or is it my MacBookPro)?

  • @TonySheog
    @TonySheog4 жыл бұрын

    Q&A: How can someone get into game engine development? Is it possible to become a game engine developer without gamedev industry experience (just being good at c++)? It feels like 95% of all gamedev jobs today are in Unity so you have to code in c# and not get any experience in c++

  • @Byynx
    @Byynx7 ай бұрын

    Now i am confused, on the string creation it calls the new function too????

  • @ziyadkader6767
    @ziyadkader67674 жыл бұрын

    what's your opinion on rust and its memory safety model ?