Пікірлер
@Valetravelgames
@Valetravelgames Күн бұрын
I would have at least 100 stutters trying to say all that
@nescafezos4265
@nescafezos4265 3 күн бұрын
I wondered how to create repeat mapped memory page...
@Whitetigercub
@Whitetigercub 4 күн бұрын
fuck this song is a banger
@LoudSunshine
@LoudSunshine 6 күн бұрын
Me mentioning that I saved a little extra money for emergencies My phone after the Google/Apple spyware heard that: 0:05
@tukars-dev
@tukars-dev 6 күн бұрын
I feel enlightened. Actually I think this is what makes zig a great language, when compared to C. I think it encourages n+1 thinking because allocators are kind of annoying so you want to feel less annoyed. I do think there are a few places with singletons (maybe a map) where n+1 approach might not be appropriate, but in general a lot of things aren't singletons...
@MasterLYT
@MasterLYT 7 күн бұрын
I had this on 2x speed because i watched the last video on it and i thought that was how the video was supposed to be lol
@couldntfindafreename
@couldntfindafreename 7 күн бұрын
As a developer with 30+ years of experience I can clearly see why "grouped element thinking" is so important and how it relates to good data oriented design.
@vixthegoat420
@vixthegoat420 7 күн бұрын
Would you look at all that stuff..... they've got allen wrenches, gerbil feeders, toilet seats, electric heaters Trash compactors, juice extractor, shower rods and water meters Walkie-talkies, copper wires safety goggles, radial tires BB pellets, rubber mallets, fans and dehumidifiers Picture hangers, paper cutters, waffle irons, window shutters Paint removers, window louvres, masking tape and plastic gutters Kitchen faucets, folding tables, weather stripping, jumper cables Hooks and tackle, grout and spackle, power foggers, spoons and ladles Pesticides for fumigation, high-performance lubrication Metal roofing, water proofing, multi-purpose insulation Air compressors, brass connectors, wrecking chisels, smoke detectors Tire guages, hamster cages, thermostats and bug deflectors Trailer hitch demagnetizers, automatic circumcisers Tennis rackets, angle brackets, Duracells and Energizers Soffit panels, circuit brakers, vacuum cleaners, coffee makers Calculators, generators, matching salt and pepper shakers
@RobertTheFoxxo
@RobertTheFoxxo 7 күн бұрын
I was fully expecting heavy to get shocked at the mention of "automatic circumcisors"
@Asdayasman
@Asdayasman 7 күн бұрын
In the context of a web application server (request/response based, everything kinda is self-contained and hierarchical), how would one go from n to n+1? (With specific examples).
@Asdayasman
@Asdayasman 7 күн бұрын
Casey out here being the hoe_math of programming.
@allenussher5884
@allenussher5884 7 күн бұрын
Good stuff. So much of getting better at programming is recognizing how your choice of system design is causing you to do more work than is actually needed. When you've come up with a design that's so simple and has so few failure points, it feels so good.
@Ewanman.
@Ewanman. 8 күн бұрын
Here's a fun game! Count every item scout has spoke out
@ShrimpoDandysWorld
@ShrimpoDandysWorld 9 күн бұрын
Heavy: Wow Scout, is impressive you know all that! Um…Scout? Scout take breath now! DOCTOR
@ShyGuyCookMaster50
@ShyGuyCookMaster50 10 күн бұрын
They’ve got: Allen wrenches, gerbil feeders, toilet seats, electric heaters, trash compactors, juice extractors, shower rods and water meters, walkie talkies, copper wires, safety goggles, radial tires, bb pellets, rubber mallets, fans and dehumidifiers, picture hangers, paper cutters, waffle irons, window shutters, paint removers, window louvres, masking tape and plastic gutters, kitchen faucets, folding tables, weather stripping jumper cables, hooks and tackle, grout and spackle, power foggers, spoons and ladles, pesticide for fumigation, high performance lubrication, metal roofing, water proofing, multipurpose insulation, air compressors, brass connectors, wrecking chisels, smoke detectors, tire gauges, hamster cages, thermostats and bug deflectors, trailer hitch demagnetizers, automatic circumcisers, tennis rackets, ankle brackets, Duracells and energizers, soffit panels, vacuum cleaners, circuit breakers, coffee makers, calculators, generators, matching salt and pepper shakers 😂😂
@egg3228
@egg3228 11 күн бұрын
Remember, when they go to Home Depot use Engineer’s phone number he has a discount
@staticsphere_
@staticsphere_ 12 күн бұрын
Scouts teeth don’t move…
@AZZEROINFINITEGG
@AZZEROINFINITEGG 12 күн бұрын
Fire🔥✨🔥✨🔥✨
@twobrosincorporated
@twobrosincorporated 13 күн бұрын
My dad when I ask if we can get ice cream on the way to Home Depot:
@fullsalvo9729
@fullsalvo9729 13 күн бұрын
eminem been real quiet ever since this dropped
@binitrupakheti4246
@binitrupakheti4246 16 күн бұрын
Isn't he basically talking about arena allocation at that point?
@xDahl
@xDahl 12 күн бұрын
Yes and no, there's more than just arenas for custom allocators.
@clivedsouza6213
@clivedsouza6213 17 күн бұрын
What was the best piece of programming advice then?
@PanicSatanic
@PanicSatanic 18 күн бұрын
Just plain wrong that this kind of thinking applies to all programming. Imagine if every process running on a server pre-allocated the amount of memory its programmers thought it would need at its peak. This is a classic case of a Dunning-Kruger applying to everyone, even folks who are experts in one area.
@rajat5856
@rajat5856 15 күн бұрын
Sorry, but it's seems to me that you are long gone into the opioid haze of excuses. VirtualAlloc on windows and similiar APIs on other platforms, just maps a virtual address space for you, instead of allocating any memory. It's when you decide to read or write to that memory, os decides to put into the RAM or swap.
@xDahl
@xDahl 15 күн бұрын
Reserving a virtual address range isn't the same as committing memory, as pointed out by rajat. Here's a test you can do to see this in action, reserve 64GB of ram (not commit) and pause the program execution. If you look at your system resource usage, you'll find that nowhere near 64GB of ram is being used. You can then commit the first few pages and write to them (caveat later), and your program still won't be using 64GB. So what's going on here? Well, all you've done is tell the OS and MMU that you wish to reserve X amount of memory pages (equating to 64GB), from then on, no amount of memory allocation will occupy that address range (you did _reserve_ it afterall). Caveat: IIRC, even if you ask to reserve and commit those pages with virtalalloc/mmap, the OS will simply reserve it and auto commit for you as you start writing to those addresses. This just means that your program will actually only use the amount of memory pages you're actively writing to, AKA; memory you're actually using. Virtual Memory is a wonderous feat of modern computing, and it's been with us for longer than you think, it is a shame it isn't taught early on.
@Kritzomega
@Kritzomega 18 күн бұрын
The jury listing the crimes i committed after the Discord chat got leaked:
@explqicot3293
@explqicot3293 18 күн бұрын
Damn I forgot he used c++ I thought he mostly used c i guess that was just for some time only
@Muskar2
@Muskar2 13 күн бұрын
It's C-styled C++ as always
@presentrama
@presentrama 19 күн бұрын
how did bro go from Scout TF2 singing Hardware Store by Weird Al to programming
@xDahl
@xDahl 15 күн бұрын
A mystery that will never be solved~
@airpods4
@airpods4 19 күн бұрын
Good video
@yessopie
@yessopie 20 күн бұрын
I think there are still many situations where "N" programming is by far the simplest and best approach. Like if you are just parsing a JSON config file on startup... Just use std::string, which is RAII. You can get huge performance improvements if you write some bespoke memory-arena string routines if you need to parse a very large log file or something. But for many things, that kind of performance just doesn't matter. j_blow said something similar about optimizing the loading in Doom... At first he thought John Carmack was an idiot for writing such inefficient code. Then he realized that you wouldn't actually gain anything by optimizing it, so Carmack did the right thing by keeping the code simple.
@xDahl
@xDahl 15 күн бұрын
What? As far as I know the code Carmack wrote was very optimized from the start. I'd like a source for this, as this sounds like news to me. As for "I think there are still many situations where "N" programming is by far the simplest and best approach", yes absolutely! I don't think it's the majority, but even a minority of cases are still cases which exist. This is unfortunately one of the things people assume about me since I uploaded the video, I don't think "N style code" is never valid, there are plenty of cases where it is (and even is the right choice); the problem is that a significant amount of people don't know about N+1&2 style code and irrationally dismiss it, and that N+1&2 style can often be easier and better. I'd also like to state that N+1&2 style code doesn't _just_ give you performance benefits, this is sadly one thing I've had to repeat over and over again in this comment section, but it gives you plenty of benefits besides performance. Honestly I'm too tired to type it out again, take a look around and you should find some comments explaining this.
@bryanedds8922
@bryanedds8922 20 күн бұрын
here for the bedhead
@T4RG3T_4CQU1R3D
@T4RG3T_4CQU1R3D 23 күн бұрын
When someone taps my shoulder chip that makes me list everything in the hardware store:
@fromjavatohaskell909
@fromjavatohaskell909 24 күн бұрын
Allocation in advance is definitely preferable and sometimes it is required (like for example in some embedded systems) - but it might be tricky when you write program driven by external data. You don't know in advance resource requirements - for example how much would you need extra memory to parse incoming JSON object? I think we might consider multistage processing - for example some preliminary parser with fixed overhead do preliminary processing and determines requirements for later stages.
@xDahl
@xDahl 21 күн бұрын
Virtual memory on 64 bit systems helps a lot when you don't know how much memory is needed for a task, as you can reserve massive ranges without committing it all. But even then there will be outliers, though I don't think most programmers will have to deal with a 128GB+ JSON file. At that point, something has gone terribly wrong.
@fromjavatohaskell909
@fromjavatohaskell909 24 күн бұрын
Agree - pools might be extremely effective. I with Java had some ability to create pools (thread heaps?) for objects. For example it might have been very helpful for processing requests in HTTP servers.
@DocDaveMan
@DocDaveMan 26 күн бұрын
“The hello kitty girl can’t be that bad” What the hello kitty girl is gonna use
@Purpleking3976
@Purpleking3976 26 күн бұрын
SCOUT VS EMINEM!!!! WHO WINS!
@Purpleking3976
@Purpleking3976 26 күн бұрын
I meant scout full power rapper
@Cosmoswuztaken
@Cosmoswuztaken 27 күн бұрын
360p Looks better
@frechjo
@frechjo 27 күн бұрын
Why do people think memory arenas are something new, or associate them with some person in particular? The first time I heard about something like that, was in the Abuse game engine, released in 1997. It's basically a Lisp interpreter, but instead of doing GC, it just clears all non global variables after each frame (or something like that, I don't remember the exact details). There's also a similar pattern in Forth, in which you save the current pointer to the dictionary, create temporary definitions, and reset the pointer back to that point when you are done (I don't know for how long it's been in use, but Forth is pretty old).
@danilomenoli
@danilomenoli 27 күн бұрын
I really don't like this Casey Muratory guy. There are much better, humbler and better teacher programmers out there you can listen to.
@xDahl
@xDahl 27 күн бұрын
Fair if you don't like him. Keep in mind that this is an excerpt from a stream of his, you can check out his videos on his channel where he presents himself a fair bit differently. But whatever floats your boat :)
@cubekoss7547
@cubekoss7547 27 күн бұрын
now do it in 8k
@xDahl
@xDahl 11 күн бұрын
I'd rather walk on lego
@haran5984
@haran5984 28 күн бұрын
not gonna lie, I liked this video a lot
@mileselam641
@mileselam641 29 күн бұрын
Or "How I learned to stop worrying and love coding in Rust". Ownership and lifetimes are not a constant concern when the language supports them out of the box.
@unimatrixz3ro226
@unimatrixz3ro226 29 күн бұрын
I really like this content, more like this plz!
@allNicksAlreadyTaken
@allNicksAlreadyTaken 29 күн бұрын
I dislike the rant about checking allocations. No one really does that. No one handles std::bad_alloc in C++ and Rust simply panics (exits the program with an error), if *any* allocations fail, so there isn't even a way to handle an allocation failure. Modern operation systems overcommit and page to disk, so there is almost never a way to have an allocation fail, except if you have limits somehow (like in a container) or you try to allocate a gigantic block of memory in one go. Exceptions suck, but they are so popular not because allocations may fail, but many other non-games software just has a lot more code that can fail. Pretty much *everything* is IO of some sort (mostly network, sometimes disk). Games usually do not work that way. I think that shows that Casey lacks a lot of perspective regarding software outside of games and frankly most existing large software projects. His opinion makes sense given his background, but with a different background the N mindset does make sense not just as an intermediate step.
@allNicksAlreadyTaken
@allNicksAlreadyTaken 29 күн бұрын
He says it applies to everything, it is very specific to video games and he is privileged to not have to work with herds of people that aren't that good at programming. Most of my time writing code is making sure it cannot be misused and there is no way to use it incorrectly. I worked in telecommunications and sadly, as with most software jobs, most coworkers are incompetent. If you write code that does as little as possible and is super fast, but is effectively broken after only a few other people have touched it, phone networks can go down and you might get woken up in the night or lawsuits might happen. Most software that is used is written by dozens of people, many of which are simply too dangerous to be trusted with code that breaks easily.
@xDahl
@xDahl 15 күн бұрын
I'm so tired of repeating myself over and over, no this isn't just specific to video games, this has existed for decades. You also make a presumption that N+1&2 style code is just so much harder to maintain, how so? Also you think Casey hasn't worked with multiple people before? Or on large code bases? Tell me more about his life, mr paparazzi
@zcizzorhandz5567
@zcizzorhandz5567 Ай бұрын
This guy is better at articulating everything I've been trying to say in the past decade and I don't seriously consider myself a lower-level dev. The same applies to all software development.
@insentia8424
@insentia8424 Ай бұрын
Funnily, the n stage was a huge wall to me. There were so many tiny things working together that I couldn't visualize it, and thus couldn't understand it and it felt extremely demoralizing and like I was too dumb for programming. Only when I ditched trying to understand that stuff and go about it other ways (largely inspired by Casey's handmade hero and other talks about programming), it all started to click and make far more sense, because I could finally visualize what is supposed to happen. Whether I'm at the n+1 stage currently... I don't know. There is probably some of the n stuff in there while prototyping a feature just because it's quicker to check if it even works.
@bruderdasisteinschwerermangel
@bruderdasisteinschwerermangel Ай бұрын
I feel like this issue is overblown in general. I still try to convince every programmer I meet that they really don't need memory allocations/the heap at all for 95% of their objects. Yes since I'm looking at this from the embedded world I am very biased. But frankly most things that I have to put on the heap are data containers (string, vector, map, set, ....). These need to dynamically change size so yeah they must go on the heap unless you have a definitive max size. The only other times something goes on the heap with a smart pointer is when it needs to cross thread boundaries. A conrete example was a large data structure (>150 KiB) that is produced in thread A and processed in thread B. I can just call unique_ptr's swap instead of having to copy the data from A's stack to B's stack.
@marcossidoruk8033
@marcossidoruk8033 Ай бұрын
For strings its useful to use a string builder pattern to avoid unnecessary allocations. For large things such as "vectors" (bad C++ name, they are really arrays) no one is telling you to not use malloc for that when needed. What casey is speaking against is small allocations (individual structs and pieces of data structures) that could have easily been grouped into a single lifetime (the lifetime of the data structure or some program specific lifetime like a frame). You don't need to know the size of a data structure beforehand to group allocations, you allocate a pool of memory of a sufficiently large size and then you assign the memory using an allocation strategy, most often a bump allocator. Wether you agree with this or not, it is an objective fact that this leads to code that is orders of magnitude faster in normal computers than RAII. I have no idea about embedded systems though.
@bruderdasisteinschwerermangel
@bruderdasisteinschwerermangel 29 күн бұрын
@@marcossidoruk8033 Yes a string builder (or std::stringstream in C++'s case) is a fine tool to use. It solves that particular problem rather well. And I also think you should absolutely always use a std::vector over manual malloc calls, solely to ensure you don't leak the memory. A bucket/pool does the same trick and I'm familiar with the pattern and I'm not opposed to it at all. My point is that is solves an issue which can be avoided quite easily. The "small allocations (individual structs and pieces of data structures)" mostly don't need to be on the heap to begin with. Containers that have a runtime determined (or even dynamic) size, yes, that's why we got vector, map and so on. But what else must go on the heap? If its size is known at compile time there's no benefit from putting on the heap aside from certain cases (like the multi threading one I mentioned). I think in a lot of ways, the "buckets" or "pools" or whatever you want to call them, do exist in the code I write, but they're just the containers. I see absolutely no reason for any ol' object (like an entity in your game) to go on the heap *on its own*.
@LinucNerd
@LinucNerd 28 күн бұрын
@@bruderdasisteinschwerermangel If I'm understanding you right, what you're saying is that data of known size and life-time should be put on the call stack whenever possible? (or the global area if appropriate)
@bruderdasisteinschwerermangel
@bruderdasisteinschwerermangel 28 күн бұрын
@@LinucNerd Yeah. And in the case where you might have multiple instances of something, you're probably gonna put them into a container of some sort. It's similar to the bucket/pool allocation to be fair. One other case where this might not work is if you work with inheritance/interfaces. Let's say component A gets a component that implements X and acts as the owner of that object. In that case you need to pass a pointer or reference. I'd probably use unique_ptr (that way A has full ownership of X) or make A non-movable and take the value by raw ptr or reference (but you have to ensure the life times align).
@earx23
@earx23 Ай бұрын
Yes, more efficient. All dynamic memory allocation is expensive. If you can do it all static, it's better. Good luck doing everything static in a complex GUI, though. I was an assembly programmer long ago, and that gave me the ability to write way more performant code than most coders, and still does. However, it just all depends on the problem.. For me, as an assembly programmer, it was hard to understand how dynamic web pages are served. .. And never forget: premature optimization is the root of all evil.
@Vitorruy1
@Vitorruy1 22 күн бұрын
That's boomer advice. The average developer doesn't even know enough optimization to do a premature one. The root of all evil nowadays is people writing code they don't need to solve problems they don't have.
@earx23
@earx23 22 күн бұрын
@@Vitorruy1 very true.
@feliciafasterthanlight5796
@feliciafasterthanlight5796 Ай бұрын
Did he really say any memory from the OS is zero by default unless you are on an embedded system? Oh have seen that error made before! That's how you end up with code that runs on every computer BUT the one you want to run it on.
@xDahl
@xDahl Ай бұрын
Correct me if I'm wrong, but memory from the OS is indeed zeroed-out by default. Linux, FreeBSD, Mac and Windows does this for security reasons. However Malloc (the allocator) doesn't necessarily do it before reusing old memory that it fetched from the OS, but that's not the OS fault, the OS gave malloc zeroed-out memory.
@deeplow4492
@deeplow4492 27 күн бұрын
@@xDahl when malloc used mmap it will get zeroed out pages from the OS, but for small allocations it uses sbrk and arenas which just refuses the same memory region without zeroing it out
@xDahl
@xDahl 23 күн бұрын
Oh I see what's meant here. See, malloc is a general purpose allocator from the standard C library, but malloc isn't the OS, so you cannot depend on malloc always giving you zero'ed out memory, but what Casey is advocating for is using custom allocators instead of malloc. When your custom allocator asks for new memory, it is zero'ed out by the OS and you don't have to do anything, and any time you need to reuse old parts, your custom allocator just zeros it out first. The cost of doing so is negligible considering the OS already does it for fresh memory. Unless you have truly unknown lifetimes and relations between allocations, you should be using custom allocators instead of malloc, thus you can rely no memory being zero when allocated. Malloc being a generalized allocator means it has to be _very_ inflexible in the assumptions it makes, thus it is also a poor fit for a lot of situations.
@gmodrules123456789
@gmodrules123456789 18 күн бұрын
@@xDahl If you want guaranteed zero memory, you would have to use calloc instead of malloc.
@Muskar2
@Muskar2 13 күн бұрын
@@gmodrules123456789 Or VirtualAlloc/mmap
@azgult
@azgult Ай бұрын
This is one of the worst takes I've heard in a while. It completely glosses over what your problem domain is, and that not all problems are amenable to the types of groupings we're talking about. This is especially true for programs where multiple things reference the same allocated structure, where it's not possible to statically reason about what may go out of scope if a part of the structure is removed. That actually hinders reuse, not helps it. The fact that reasoning at the element level is also *crucial*. It's the backbone of functional programming, and by forcing reasoning at a more holistic level you set yourself up for failure if your application changes direction, makes it easier to make mistakes about what you think your application will require, and ultimately complicates your overall architecture, all for the benefit of simplifying allocation specifically. This is really the crux to me: It is good to not have to think about allocations. They are a distraction from making code *correct*, and that is usually more important than performance. I also disagree on the argument that this reduces failure greatly. It does reduce the *points* of failure, but they're all homogeneous. Your 1000 allocations of 1kb will fail as often (actually slightly less often depending of paging) to your 1 allocation of 1mb. Even your case of 'literally not failing' is a failure case.
@xDahl
@xDahl Ай бұрын
I don't quite see your reasoning, but you mention "functional programming", are you saying that what Casey is advocating for won't work in a functional paradigm specifically? Or is this a more general claim?
@bryanedds8922
@bryanedds8922 20 күн бұрын
@@xDahl It's a general claim, I believe. Pooling resources does inherently create some cross-system coupling. By default, you're going to want to reduce coupling across your system. However, there are many cases where this coupling more than pays for itself in terms of massive performance advantage. Like everything else, you just need to look at things case-by-case to see if the trade-offs are worth it.
@xDahl
@xDahl 20 күн бұрын
@@bryanedds8922 I will happily admit that I don't understand what you're saying here, and that's not a failure on your end to communicate, it's on my end to comprehend.
@edgyzero6305
@edgyzero6305 Ай бұрын
I can see this type of thinking being a god send in C where keeping track of many small allocations is quite difficult, however in Rust it really doesn't seem to be an issue whatsoever after adjusting to the initial friction of the borrow checker. Of course this style of allocation is still useful for large applications that need large chunks of memory to be reused frequently across different parts of the application but for average use cases of I/O when you already have the borrow checker to handle the "little" pieces the extra overhead of implementing a large allocator seems unnecessary. As much as I love performance and efficiency I think it's good to have the application in mind, if implementing a more sophisticated architecture will net negligible gains only noticeable by nanoseconds then it seems more reasonable to opt for a simpler design. My main point is that I find what he is saying to be useful but not for all use cases and applications as is insinuated.
@blarghblargh
@blarghblargh Ай бұрын
performance is not the only benefit from an architecture that bundles all allocations together. he talks extensively about aggregating failure points. rust doesn't get that benefit from the borrow checker.
@edgyzero6305
@edgyzero6305 Ай бұрын
@@blarghblargh I certainly don't mean to be dismissive of this architecture but I do think I'd need to see it in action to really get it. To me currently the borrow checker really doesn't seem to cause much issues, at least on small scales. I know he mentions thinking about applications at small scales as being the difference between the average programmer and a pro but it does seem like the small approach is valid for small apps. Certainly when making a game the overhead/sys calls for memory greatly increase for thinking about things at a small scale.