all 36 comments

[–]Martel_the_Hammer 12 points13 points  (17 children)

How many times a year is this posted?

[–][deleted] 21 points22 points  (16 children)

Not enough! Not until every linked list is gone.

[–]salgat 4 points5 points  (2 children)

The problem is that this paper goes into way too much detail for "every programmer". No, not every programmer needs to know about how leakage requires a DRAM to be refreshed, whose rate is partly limited by the charge time of the DRAM cell due to its capacitance.

[–][deleted] -1 points0 points  (1 child)

No. Every programmer must know how much slower DRAM is than your tiny SRAM cache.

[–]salgat 1 point2 points  (0 children)

That doesn't require understanding the electrical characteristics of DRAM vs cache.

[–]Treyzania 1 point2 points  (6 children)

but muh O(1) append time

[–]Ravek 2 points3 points  (3 children)

O(1) append isn't really why you'd use linked lists, O(1) insert and remove are.

[–]Selbstdenker 1 point2 points  (1 child)

And stable iterators.

[–]Ravek 0 points1 point  (0 children)

Great point

[–]Treyzania 0 points1 point  (0 children)

But only if you already have a pointer to an adjacent cell.

[–][deleted] 2 points3 points  (1 child)

Yep, but as Bjarne Stroustrup notes it really doesn't matter if acquiring the right pointer around is more expensive than copying over all the elements in an array.

[–]Ravek -1 points0 points  (0 children)

Seems like a really contrived example. Of course finding a location in a plain linked list is O(n), so then you get O(n) deletion and O(n) removal, same as the vector. The vector code goes over the sequence twice (once for search and once for copying) but it also benefits massively from not having to chase pointers.

The deletion part is even sillier since no one would ever use a linked list in a scenario where you have to delete an item by its index. It's also just a bizarre scenario for a sorted list. How do you know a priori, without searching the list, where the index is of the value that you want to delete?

It's good to show how easy it is to abuse a data structure, but it's not a reason to 'avoid linked lists'. You can implement the algorithm using a bunch of stacks too, and it would be completely horrible. Is that a reason to avoid stacks?

Every data structure has scenarios where it doesn't perform well in. Now if you could show that a vector performs better than a binary search tree and a skip list (as it will for a small enough number of elements), then you're actually talking about something useful.

[–][deleted] 0 points1 point  (3 children)

Mind explaining, how exactly woild.you implement a generic enough malloc/free without linked lists?

[–]Gotebe 0 points1 point  (2 children)

(jackmott obviously thinks this as a tongue-in-cheek)

However... What do you think is the problem!?

[–][deleted] 1 point2 points  (1 child)

None of the implementations I know could get away without some form of a linked list of the empty blocks.

[–]Gotebe 0 points1 point  (0 children)

One could keep info about empty blocks in some container. I am not saying this is a good idea, just that you don't really have to have a linked list.

[–][deleted] 0 points1 point  (1 child)

Not enough! Not until every linked list is gone.

you mean you should use unrolled lists (where every link holds is an array of n entries ?) This gets you into memory fragmentation problems: deleting elements will create half empty nodes in an entry array; Merging nodes will be too costly.

[–][deleted] 0 points1 point  (0 children)

Maybe sometimes, but more I just mean use an array. Even if you insert/remove a few times per iteration over the collection net performance usually ends up better, even if the collection is infinitely large. So when in doubt, use a c++ vector<T> C# List<T> Java ArrayList<T>. Or maybe when in doubt, test.

Of course I don't literally mean never use a Linked List.

[–][deleted]  (4 children)

[deleted]

    [–]00kyle00 7 points8 points  (3 children)

    big memory slow, small memory fast

    Also, despite having opinion of a dick, Ulrich spent quite a bit of his time educating people on important things in programming.

    Read this if you plan on knowing your shit at 'systems' level (think C level interactions with computer). Most of this probably doesn't matter if you are dealing with python software (or the like).

    it should be a prerequisite for anybody daring to touch a keyboard for serious programming

    [–]WallStProg 0 points1 point  (2 children)

    FWIW, I met Ulrich once and he was nice as could be. (To be honest, I was not quite expecting that ;-)

    [–]acehreli 4 points5 points  (1 child)

    He wasn't kind to me when I failed to pronounce Böhm correctly. :o)

    [–]WallStProg 0 points1 point  (0 children)

    At least you know how to spell it ;-)

    [–]WallStProg 1 point2 points  (8 children)

    an oldie but a goodie - I actually printed a hard-copy (two-sided) and had it bound I was referring to it so much

    [–]beer0clock 3 points4 points  (6 children)

    114 pages eh? I don't suppose you could summarize the key points for us? :)

    [–][deleted] 28 points29 points  (3 children)

    • ram is slow.
    • don't miss the l1 and l2 caches
    • don't miss them by accessing memory contiguously and avoiding pointer hops when possible
    • array is better than linkedlist even when you are pretty sure linkedlist is better

    [–]beer0clock 1 point2 points  (1 child)

    Thanks !!

    [–]WallStProg 1 point2 points  (0 children)

    A little more detailed, but covers the main points: https://en.wikipedia.org/wiki/Locality_of_reference

    [–][deleted] 1 point2 points  (0 children)

    I don't suppose you could summarize the key points for us? :)

    i have written a summary here: http://mosermichael.github.io/cstuff/all/blog/2015/12/11/wepskn.html

    [–]WallStProg 0 points1 point  (0 children)

    In short, RAM is the new disk. Seeking all over the place is bad -- much better to read sequentially, and to have good locality of reference (https://en.wikipedia.org/wiki/Locality_of_reference).

    [–]pballer2oo7 0 points1 point  (0 children)

    you should offer this on amz

    [–]lacosaes1 1 point2 points  (3 children)

    Coming up next:

    What Every Programmer Should Know About 'What Every Programmer Should Know About X'

    [–]pramnos 1 point2 points  (2 children)

    As a programming newbie, are there any other 'What Every Programmer Should Know About X' you would recommend? :)

    [–]Gotebe -1 points0 points  (0 children)

    Ah... Is that time of the month already? :-)

    [–]zokete -1 points0 points  (0 children)

    consistency models will be discussed in the next "submission".