TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Baby's First Garbage Collector

217 pointsby daw___over 11 years ago

7 comments

recuterover 11 years ago
So every once in a while I come across old timey C optimizations in the spirit of Duff&#x27;s device or bit twiddling to swap variables, &#x27;etc &#x27;etc...<p>While they have a certain kind of charm to them they seem to be almost universally bested by increasingly mature compilers and complex (or virtualized) hardware.<p>So I&#x27;m kind of coming to the conclusion that clever pointer arithmetic games and even manual malloc&#x2F;free are <i>increasingly</i> futile unless you&#x27;re targeting embedded devices. If a young language like Go gets you at least in the same ballpark as C with a relatively immature GC and even toy implementations like the OP take you rather far these days... when is coding without a garbage collector even really defensible anymore?<p>I&#x27;m not trolling. I think pointer arithmetic is neat and the aforementioned &quot;optimizations&quot; are magical and possibly my generation has missed out on something wonderful. Seems it just isn&#x27;t often practical to do that sort of thing anymore.<p>Edit: I&#x27;d like to stress that I wasn&#x27;t talking in absolutes, and asking rather than telling. I&#x27;m not sure how to phrase my post better, made some edits nonetheless.
评论 #6872226 未加载
评论 #6873791 未加载
评论 #6872204 未加载
评论 #6871931 未加载
评论 #6874352 未加载
评论 #6872035 未加载
评论 #6872153 未加载
评论 #6871872 未加载
评论 #6875343 未加载
评论 #6872389 未加载
phamiltonover 11 years ago
Not having studied the topic in depth, my first thought is whether true pointers and a garbage collector can coexist (without artificially removing parts of the language). The big condition for knowing if something is still in use is whether any references exist to it. But in a language like C , you could cast a pointer to something else (like a void pointer for some quasi generic linked list), store it somewhere, and then cast it back later after garbage collection has run. That seems like a problematic situation. So is completely giving up on pointers (or just never doing tricky things like casting or pointer arithmetic) a requirement to having a garbage collector?
评论 #6872343 未加载
评论 #6871670 未加载
评论 #6871643 未加载
评论 #6871603 未加载
评论 #6872780 未加载
评论 #6872104 未加载
dysocoover 11 years ago
Now THIS is the kind of articles I want to see in HN.<p>Saved for later reading, seems very interesting and well explained.
评论 #6871922 未加载
robertkover 11 years ago
I don&#x27;t understand. When sweep frees an object, it invalidates the &quot;next&quot; object of the previous object in the linked list, breaking the traversal next time a gc() is called. Doesn&#x27;t the linked list have to be patched? (e.g., keep track of &quot;prev_object&quot; and set its next to unreached-&gt;next before freeing unreached)
评论 #6872582 未加载
mamcxover 11 years ago
That was actually very easy to understand!.<p>Thanks for that. I&#x27;m thinking in build a toy language and this make on magic thing die..
signa11over 11 years ago
storing the &#x27;mark&#x27; bit with the objects themselves is not so good for COW semantics, but should be <i>just</i> fine for this toy example i think...
kimonosover 11 years ago
Nice post! It&#x27;s very precise. I didn&#x27;t have a hard time understanding it. Thanks for sharing!