ARRAYLIST VS LINKEDLIST

2024 ж. 15 Нау.
44 300 Рет қаралды

In this one, we explore how ArrayLists and LinkedLists works at memory level and how scripting languages handle their "arrays."
Sign Up to CodeCrafters:
app.codecrafters.io/join?via=...
Follow me on twitter:
/ coredumpped
Follow me on Github:
github.com/jdvillal
Questions and business contact:
contact.coredumped@gmail.com

Пікірлер
  • 20:34 Fuck I need that card in my wallet

    @scheimong@scheimong2 ай бұрын
    • Me too, I hope he sells it as merch one day

      @nxthingbutv0id958@nxthingbutv0id958Ай бұрын
    • JS is the new PHP

      @luanlmd@luanlmd2 күн бұрын
  • baby wake up core dumped just uploaded

    @ezsnova@ezsnova2 ай бұрын
    • 🤣lmao seriously tho

      @yumyum7196@yumyum71962 ай бұрын
    • I prefer 'baby wake up core dumped'

      @ivankudinov4153@ivankudinov4153Ай бұрын
  • Javascript bashing ✅ Engaging and interesting systems programming content ✅ Funny retorts for armchair programmers ✅ Im so glad i found this channel early and subbed

    @Blezerker@BlezerkerАй бұрын
  • best animation quality yet, the pointer hell is somehow very understandable

    @naautilus0@naautilus02 ай бұрын
    • pointers are easy

      @skilz8098@skilz8098Күн бұрын
  • This is the single best video on the topic ever! When i was studying cs, our prof didn't even try to explain how data is stored, he just moved on to using pointers, i had no previous experience with them and was like wtf are pointers. You put it all flawlessly into words AND animations, and a picture is worth a thousand words. Great video that brings so much clarity, every cs undergrad needs to see this. Thanks a lot!

    @MrPilotStunts@MrPilotStunts2 ай бұрын
    • There's something about real life coaching that doesn't come near as well organized/animated videos do. All students should know that videos are 100x better at converting knowledge to intuition and they should treat in-class lectures/tutorials as the sub-materials for their learning.

      @GTAdkdk@GTAdkdk3 күн бұрын
    • @@GTAdkdk absolutely, well said

      @MrPilotStunts@MrPilotStunts3 күн бұрын
  • What a spectacular video, I'm just creating my own programming language and this fits me like a glove.

    @giankadev3026@giankadev30262 ай бұрын
  • Nitpick: JavaScript engines typically do implement arrays as continuous blocks of data, and generally setting just one item at index 10k will then allocate up to that number (or more). They just have to pessimise the array for the holes in it.

    @AapoAlas@AapoAlas2 ай бұрын
    • I remember writing a filter and it was returning null items, you have to be very careful with JS

      @wil-fri@wil-fri2 ай бұрын
    • They use C++ struct arrays, not normal arrays, class arrays or vectors.

      @about2mount@about2mount2 ай бұрын
  • yes, I am to watch a livestream of yours solving CodeCrafters challenges Jon had done the same a week ago with Git, and I watched through the entire thing. that was indeed really interesting, and I'd like to solve these myself too 😊

    @dzuchun@dzuchun2 ай бұрын
  • absolutely one of the best channels out there right now. u go even more indepth than some of my college classes and make it seem easy. big ups bro

    @seid44@seid442 ай бұрын
  • I remember really struggling with these sorts of topics when I was at university. These are some of the best explanations for OS/low-level programming concepts I've ever come across!

    @michaelciccotosto-camp4033@michaelciccotosto-camp40332 ай бұрын
  • Just found your channel! Really happy to see you just uploaded. I love your intuitive visuals to explain all sorts of mechanics

    @rubenvanderark4960@rubenvanderark49602 ай бұрын
  • that's why i propose all scripting languages should be pseudo compiled: the bytecodes are as specific as assembly instruction (not as much but you get it), and the generic stuff actually happens at "compile" time, every scripting languages should do that, even at the cost of longer "compile" time. I want to do one, but I struggle everytime when making the parser so you will probably never see that. Also in java, if it's not a primitive, it's an object, every arrays of non-primitives in java are arrays of objects, and you can verify it with the JNI.

    @darkfllame@darkfllame26 күн бұрын
  • Incredible work with these videos so far. Hitting all the key points at just the right level of detail. The animation work is just... * chef's kiss * Keep it up 🙌

    @biasedbit@biasedbit2 ай бұрын
  • I absolutely adore JavaScript, but concurrently adore these videos. The quality is capital. I aspire to produce quality material like this.

    @stevebrownlee6141@stevebrownlee614114 күн бұрын
  • Waited for this video after the previous teaser. Ur videos are the most accurate on the subject there are

    @Firestorm-tq7fy@Firestorm-tq7fy2 ай бұрын
  • The quality of this channel is amazing, I wish you all the success and I'm excited to see many more interesting and educative videos like yours, you have a good way of getting your point across... I'm a

    @lukasaudir8@lukasaudir814 күн бұрын
  • George, your videos are really awesome! I already knew all these concepts but I have never seen them better explained. Anyway, I love C and Assembler because they are teaching how computers work...😊

    @knofi7052@knofi7052Ай бұрын
  • Thank you so much for this video, excellent explaination! I have a question, though: as you showed, in languages like Rust, besides specifying the array's size, it's also necessary to specify the data type (integer, float, etc...), and from what I understood, it's because this way the compiler already knows how many bytes to read for each element. However, at 19:45, in the case of Python, how does the interpreter know if, once a pointer is dereferenced, the retrieved object is an integer, a string, or another element with indefinite length? Because according to your (beautiful) animation it seems like every object has it's own specific size.

    @mariospada00@mariospada002 ай бұрын
    • Interpreters attach 'tags' to values in memory, so when the value is needed, it first reads the tag to identify the type of the value and know how many bytes to read. The answer is explained in my video: The size of your variables matters.

      @CoreDumpped@CoreDumpped2 ай бұрын
  • You are back🎉

    @ShubhanshuMishra@ShubhanshuMishra2 ай бұрын
    • Yes , really good

      @labCmais135@labCmais1352 ай бұрын
    • Heeeesss baackkk

      @silloo2072@silloo20722 ай бұрын
  • I learn so much deim your videos!! Thanks a lot !!! I'm waiting for the next one!

    @loic1665@loic16652 ай бұрын
  • Love the quality of the videos I will recommend other people in my class to them because they’re concise and easy to understand. Keep it up!

    @digggggg898@digggggg8982 ай бұрын
  • About 17:45, I'm no great expert on system programming, but the severity of data locality is unlikely severe. The cost of pointer-based array instead of a template array resides in the unpredictable position of object allocation, which confuse the CPU cache prefetcher. In reality, most workload allocates objects (as each object in the containing array) closely or in a predictable fashion, so prefetching works adequately well. And of course, pointers are still grouped together as always. For example, if we add items to a list in a loop, it is trivial for the CPU prefetcher to assume the next approriate location. Hotspot specifically, each thread has its own thread heap, so as long as the array/list is not multithreaded (which is unlikely), the pattern will be maintained. Moreover, with the nature of GC, the compacting phase will very likely move spreaded objects all over the heap to a single location, both avoiding fragmentation and maintaining the fetch pattern. There are exceptions, like if a BaseType array could contain both DerivativeType1 and DerivativeType2 with completely different object layout (only possible with reference-based array), then it's difficult for the CPU to make a good sense of the fetch pattern, which will likely suffer from "data locality". But as always, the template array would also suffer from this, so it's rather an unfortunate universal technical difficulty.

    @kienha9036@kienha90362 ай бұрын
  • Amazing video. And thank you for not pedaling surfshark or some unrelated crap. Video bookmarks would be welcome!

    @elzabethtatcher9570@elzabethtatcher9570Ай бұрын
  • I recommend everyone starting to understand the data structure to subscribe this channel and save this video, well done very nicely demonstrated!

    @azadomer5273@azadomer52732 ай бұрын
  • I wasn't able to leave a comment on your post from yesterday but I guessed arrays and I was right! I love these deep dives

    @deathdogg0@deathdogg02 ай бұрын
  • I've been working with Java for almost 20 years, and I don't think I've ever thought about what happens when you remove an element from an ArrayList. Thanks for the eye opener.

    @ZeroUm_@ZeroUm_2 ай бұрын
    • Me too, but with Go. Now I understand the motivation for slices vs arrays

      @SoniaHamiltonSnowfrog@SoniaHamiltonSnowfrog2 ай бұрын
  • I did try to use the *void pointer once! It was hilarious when you mentioned it

    @Hersonrock12@Hersonrock122 ай бұрын
  • One of the best videos I ever watched in my life

    @code-monet9468@code-monet94682 ай бұрын
  • What a fantastic video! Now all I want is to program in Assembly to learn how really an computer works, and to optimize all those inefficiencies those languages introduce! Great presentation 👌

    @SPimentaTV@SPimentaTV2 ай бұрын
  • no need to be so self-conscious at the end there. this channel is great

    @derDooFi@derDooFiАй бұрын
  • Very good video, this is the kind of teaching that works for me so thank you

    @user-do1eg2kt3v@user-do1eg2kt3v2 ай бұрын
  • It should be pointed out that the cache behavior of linked lists is NOT inherit to the linked list structure but rather to the allocator used to allocate the nodes. If we have an allocator allocators linearly the nodes will be located in memory in exact the same way as with the array. Alternative approach is to store enough elements in each node so that a full cache line is always used. Removal and addition from the middle of a node can be solved with splitting and merging. Also I am certain that pretty much all javascript interpreters really do use arrays whenever possible and only resolve to hash map as a fallback when the wasted size is too much or keys are some other type than numbers. This is not too difficult to implement internally and the performance boost is significant.

    @krystofjakubek9376@krystofjakubek93762 ай бұрын
    • This is very important to note. I also think iv read v8 uses property access for very small and likely to not be modified arrays. This way it can do direct property access without hashmap lookup or array indexing.

      @huben_1337@huben_13372 ай бұрын
  • Hi, the video has been pretty interesting so far. Just a suggestion: please put the link to the previous videos you recommended. Otherwise, in a year or so, it will be much harder to find. Unfortunately, KZhead showed exactly where the current video is in the channel's timeline.

    @pedroivog.s.6870@pedroivog.s.68702 ай бұрын
  • I have yet to see the combination of a linked list and array list in the wild that I was taught in my AlgoDat course and never again afterwards. It stored the data in a big array that can be relocated to grow, but also a separate mapping from indexes to array offsets. That sounds like a linked list (just with array indexes instead of full pointers) that enforces some form of memory coherence for both list nodes and data. As far as I know, you can refine this concept to a linked list of array slices, which is how text editors support efficient cutting and pasting of text.

    @D0Samp@D0Samp2 ай бұрын
  • i recommended the first 3 videos in this series to some computer science students i was tutoring because i felt like they went in depth into these concepts, while at the same time using terms and concepts that beginner programmers are familiar with. i felt like this video used a lot more terms and concepts which might be difficult for beginner programmers to understand compared to the last three. i think this series would be better for introductory students if the smaller concepts mentioned in this video like data structures, time complexity, etc. had heir own video before having a video about dynamically sized collections

    @sa-hq8jk@sa-hq8jk2 ай бұрын
    • in other words i felt like the pacing in this series took a sharp turn that might be too overwhelming for me to be able to recommend it to other computer science students. judging by the pacing of the first three videos in this series, it seemed like these videos were attempting to cater toward beginner-intermediate programmers with around a year of experience, but this video didn’t come across that way, although i may be wrong in my assumption for the targeted audience of these videos

      @sa-hq8jk@sa-hq8jk2 ай бұрын
    • @@sa-hq8jk I think there is enough context to understand what a datatype is without giving the textbook definition of what a datatype is (which i doubt will be helpfull to anyone anyway). A definition of time complexity would probaply have been nice, it is easy to understand and aply in these cases and can also easily be googled if needed.

      @someonespotatohmm9513@someonespotatohmm95132 ай бұрын
    • @@someonespotatohmm9513 i didnt mean what exactly a data type is, but more of how a struct is a type which combines other types, and how they are grouped together in memory and interpreted by the compiler and by memory

      @sa-hq8jk@sa-hq8jk2 ай бұрын
  • The content is great. Would be interesting to see your overviews about how rust's compiler works and about compilers theory in general. As well as interpreters actually.

    @sergeylypko5817@sergeylypko5817Ай бұрын
  • this content is pure gold!

    @eddyvytime@eddyvytime2 ай бұрын
  • Amazing as always Would love to watch those streams

    @Albert-nc1rj@Albert-nc1rj2 ай бұрын
  • Great videos, thank you for your efforts!

    @diogenes_of_sinope@diogenes_of_sinope2 ай бұрын
  • “This explains why we use zero instead of one for the first element” What a hero 🙌. Finally a non-stupid “programmers just count from zero” explanation

    @mhFFFFFF@mhFFFFFF2 ай бұрын
  • Wow, so informative, thanks so much. I’d watch a live coding session.

    @JamyGolden@JamyGolden2 ай бұрын
  • This channel is about to blow up🎉

    @ejon@ejon2 ай бұрын
  • What a gem of a channel. Keep it up!

    @thecrazyeagle9674@thecrazyeagle96742 ай бұрын
  • you've mentioned about thinking to solve codecrafters challenges on stream. Yes please!

    @sameerakhatoon9508@sameerakhatoon950816 күн бұрын
  • Omg I loved this video. Super cool to know how python’s list works under the hood. Can’t wait for what you’ve got next!

    @sidreddy7030@sidreddy70302 ай бұрын
  • More reasons to hate JS :D (And yes to the streams) Also if you intend to expand your community on other platforms a discord server might be a good idea too.

    @pritonce6562@pritonce65622 ай бұрын
  • You are very good please continue like that and I will be happy if you touch on the assembly perspective of the things too 😄

    @nexby323@nexby3232 ай бұрын
  • i love that little departure to interpreted language land

    @weakspirit_@weakspirit_2 ай бұрын
  • Linked lists are for tape storage. Similar structures are used for block or heap storage.

    @7th_CAV_Trooper@7th_CAV_Trooper15 күн бұрын
  • Thanks. I had always assumed ArrayList was just some sort of alias for a Deque, but now I know, it's just a dynamic array type. Java is one of those languages that I've avoided fully learning and any language that reuses that name for a container type too. As it is now, I probably have far too much knowledge of Java.

    @anon_y_mousse@anon_y_mousse2 ай бұрын
  • Maybe it would be better to say that modern JS JIT compilers, like V8, often optimize arrays?

    @fdb-js5uh@fdb-js5uh2 ай бұрын
  • You are doing revolutionary work bro Keep going ,keep posting more often

    @indiannews544@indiannews5442 ай бұрын
  • 12:03 did you cousin also write a getter for "self.lenght" (of self.items[self lenght]) to be the same value as "self.length" ?

    @johnabrossimow@johnabrossimow2 ай бұрын
  • The Lua Table has entered the arena.

    @c4cypher@c4cypher2 ай бұрын
    • It would be interesting to see what Lua’s cache hit & miss rate is compared with other languages…

      @VaughanMcAlley@VaughanMcAlley2 ай бұрын
  • your content is 👑. my kids will study from this channel one day 🥹 and their kids 😇 and their kids kids for generations learning low level concepts and rust. 🥂

    @kossboss@kossboss2 ай бұрын
  • God please never stop making vids my guy AGHHHHHHHHHHH

    @liburnkrasniqi4003@liburnkrasniqi400320 күн бұрын
  • Thanks for the knowledge!

    @samaellovecraft@samaellovecraftАй бұрын
  • Really great video, although I would have liked it if you talked about bounds checking in a normal array when you were talking about indexing out of bounds

    @xyz-vrtgs@xyz-vrtgs2 ай бұрын
  • Please do Hashmaps next and how are its elements linked and how does it look like in memory

    @Darkev77@Darkev77Ай бұрын
  • Excellent videos. Love your channel!

    @abombfuenmayor@abombfuenmayor2 ай бұрын
  • i wish i had the opportunity to access all these kind of videos when i was studing computer science!

    @yeknomhtooms@yeknomhtoomsАй бұрын
    • Me too!

      @CoreDumpped@CoreDumppedАй бұрын
  • Amazing video!

    @randykamindo4795@randykamindo47952 ай бұрын
  • Very well explained, these kinds of animations are extremely useful.

    @KeshavKumar-gc9pu@KeshavKumar-gc9pu2 ай бұрын
  • Yet another banger from project CD!

    @stefanmladenovic2040@stefanmladenovic20402 ай бұрын
  • This is incredible

    @sashibhushanarajput1194@sashibhushanarajput11942 ай бұрын
  • amazing video!

    @PedroShin@PedroShin2 ай бұрын
  • Excellent!

    @bobsprite6711@bobsprite67112 ай бұрын
  • Despite its quirks I love JavaScript for many reasons, one of which is that we want better performance in arrays, we can use typed arrays. The hash map approach is quite clever IMO, since in most JS code you won't be looping more than a few hundred (or few thousand at the most) times in a normal array, and if you see doing more than that, then well, you should probably reconsider your approach. All about being the right tool for the job. And if JS is just too slow, you've got WASM. And if WASM is too slow.......... then ditch JS/WASM and build a native app. 🤣

    @DrakiniteOfficial@DrakiniteOfficial25 күн бұрын
    • Yes I agree, the right tool for the right job. What I really dislike is that people trying to convince the world that JS should be used everywhere.

      @CoreDumpped@CoreDumpped25 күн бұрын
  • Good content, thx!

    @timur-yusipov@timur-yusipov2 ай бұрын
  • This was indeed a banger

    @SoreBrain@SoreBrain2 ай бұрын
  • May I give two thumbs up ?

    @lucianobestia@lucianobestiaАй бұрын
  • love your videos

    @bruno-dv5qq@bruno-dv5qqАй бұрын
  • Thankyou so much for these videos plz keep making them they are so good

    @mayureshpisat2274@mayureshpisat22742 ай бұрын
  • Be aware that modern javascript engines optimises arrays if they have no holes (java like) and even more if they are of the same type (c like) : check for SMI, DOUBLE_SMI, HOLEY_SMI, etc js arrays. So modern js engines are no more just an interpreter but also a list of runtime JIT compilers run depending of the context of the running code (the more a bit of code is run the more it uses the most complex JIT compiler with the most optimisation). hence why js nowadays can be as fast as some compiled languages.

    @alfredomoreira6761@alfredomoreira67612 ай бұрын
  • I think when he says ‘and so Forth’ he’s actually telling us what programming language to use.

    @Method5440@Method54402 ай бұрын
    • 😂

      @silloo2072@silloo2072Ай бұрын
    • We are 2 orange S

      @silloo2072@silloo2072Ай бұрын
  • I would have never suspected that an IT person can actually explain something well enough for people to understand. Good job buddy

    @bartekabuz855@bartekabuz8552 ай бұрын
    • The reason why most programmers are bad at explaining things, is that they don't fully understand most of the things they would try to explain. And the reason for that, is that most of the time they were given a surface level explanation themselves, and they just accepted it.

      @tonchozhelev@tonchozhelev2 ай бұрын
    • ​@@tonchozhelev EXACTLY

      @not_kode_kun@not_kode_kun2 ай бұрын
    • Programmers and IT people aren’t the same

      @vimandmanyothers554@vimandmanyothers5542 ай бұрын
    • @@vimandmanyothers554 it shouldn't be the same, i agree, but sadly the line is very blurry these days. a lot of programmers nowadays have no real clue what their code is actually doing, all they care about is whether it works or not. this stems from the overly-corporate nature of the modern internet and digital world. as long as it gets them money on the short term, who cares if it's performant, well-written, robust code? the mindless consumers certainly don't, so why should the multimillion dollar companies care? sad world we live in

      @not_kode_kun@not_kode_kun2 ай бұрын
    • @@tonchozhelev I have en education in embedded systems and having watched all the few videos they've done so far I've already learned several important things that no-one bothered to explain about how different data-structures are implemented by the compiler and why/how that has significant performance implications.

      @3osufdh4rfg@3osufdh4rfg2 ай бұрын
  • another great video

    @AlleBalle54@AlleBalle54Ай бұрын
  • The early bird gets the typo

    @diyathkumara2443@diyathkumara24432 ай бұрын
    • Fixed, thanks :D

      @CoreDumpped@CoreDumpped2 ай бұрын
    • @CoreDumpped Thank you for all the effort you put into crafting explanations + animations even a newbie like me can grasp so easily 🙏

      @diyathkumara2443@diyathkumara24432 ай бұрын
  • In Lua arrays are done the same way as in JS: they are in fact maps with values being indexed by numeric indices

    @keeprocking3620@keeprocking36202 ай бұрын
  • I created a linked list in C with two levels of indirection with varying orders of magnitude up to a billion elements. However, I never got valgrind to report cache misses above 0.7% when pushing all, then accesseing all then popping all. I understand that valgrind will report a simulation of the cache rather than the actual cache, but it was the best I could do to measure because my kernel does not have perf.

    @xBiggs@xBiggs2 ай бұрын
  • Thanks

    @jaya_surya@jaya_surya2 ай бұрын
  • pointer arithmetic was baked directly into intel 8086 cpu instruction set, no wonder systems programming langugaes at the time would also reflect the feature in their syntax

    @L1Q@L1QАй бұрын
    • Does this has anything to do with that take that I've been recently reading a lot claiming that C beats everything because CPUs are designed to be 'C-compiled code' efficient?

      @CoreDumpped@CoreDumppedАй бұрын
  • There‘s no way i was too lazy to comment „Dynamically sized data structures“ on yesterday’s post 😂 I had it 😭😭

    @yarrakobama3417@yarrakobama34172 ай бұрын
  • Your cousin may know more than me, but he still misspelled "length" in that code :P 11:50

    @drf289@drf2892 ай бұрын
  • Thanks for your hard work!!!🎉

    @young_oak@young_oak2 ай бұрын
  • which tools are you using to create these animations. looks pretty good

    @Boronesss@Boronesss2 ай бұрын
  • Man this animations Where were they for all these years?

    @sevos@sevos2 ай бұрын
  • @14:59, is it not possible in this case to move the first element to the right and then update the base memory address to its moved location?

    @Darkev77@Darkev772 ай бұрын
  • excellent

    @kiwiladi@kiwiladi15 күн бұрын
  • absolute mad lad

    @shant0@shant02 ай бұрын
  • 20:34 i REALLY need this card. Coredumped plz

    @Blezerker@BlezerkerАй бұрын
    • Selling them could cause Oracle to sue me since I don't have their legal permission to use the product name "JavaScript". I've been thinking about using "JS" instead, but don't know if people would buy it.🤔

      @CoreDumpped@CoreDumpped29 күн бұрын
  • afaik js arrays are actual arrays and not hashmaps... you can do array.string_key = value because like everything else js array is ALSO an object, but it contains an array as well, you are just assigning a property to the array object. If you do array[12]=some_val to a new array you will see the length actually change but if you do array.string_key=val length does not change... so basically it is {[,,,,,,,,,,,some_val], string_key: val}, js engines optimize it anyways

    @devnarula6733@devnarula67332 ай бұрын
  • If only I had you as my professor

    @Nerdimo@Nerdimo2 ай бұрын
  • Please do streams would be so nice

    @kleinmarb4362@kleinmarb43622 ай бұрын
  • I've been wondering for some time now, what do you use to animate your videos?

    @Fowdre@FowdreАй бұрын
  • Great video!

    @tacklemcclean@tacklemcclean2 ай бұрын
  • Hey Core Dumped, it would be so cool if you could make a vid on what object orientated programming is

    @Kardiiacc@KardiiaccАй бұрын
  • 4:30 I'm pretty sure it's APL that invented the bracket notation for array elements.

    @gtgunar@gtgunar2 ай бұрын
  • Nice.

    @philtoa334@philtoa3342 ай бұрын
  • If you really want to defend linked lists, you need them to be doubly linked and you need an algorithm that doesn’t just add and remove individual elements in the middle: you need an algorithm that shuffles big chunks of multiple linked lists around in unpredictable ways. In that case there *might* be an advantage to using linked lists. Linked lists get a bad rap for good reason (caching) and for bad reason (lack of imagination).

    @pauljarski7590@pauljarski759011 күн бұрын
KZhead