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.

Using Uninitialized Memory for Fun and Profit (2008)

46 pointsby frontsideairover 10 years ago

6 comments

userbinatorover 10 years ago
Due to multilevel caches I doubt this would be so applicable to modern systems - the index-set representation takes several times more memory and naturally requires lots of random accesses, which are bad for caches. In some ways, it&#x27;s no longer a time-space tradeoff: smaller <i>is</i> faster.<p>Also, initialising the space doesn&#x27;t take so long; REP STOS on x86 is <i>fast</i> since it can write an entire cache line at once: <a href="http://ptspts.blogspot.ca/2014/10/on-speed-of-memset.html" rel="nofollow">http:&#x2F;&#x2F;ptspts.blogspot.ca&#x2F;2014&#x2F;10&#x2F;on-speed-of-memset.html</a>
评论 #8711242 未加载
评论 #8711930 未加载
gizmo686over 10 years ago
Python uses a similar trick in its internal allocater (pymalloc) [1]. Given a memory address, pymalloc determines if it controls it by computing what would be the base of the arena containing said address. It then finds the index of the arena (or trash) at a constant offset from the base. It then uses the index to check a vector of all the arenas that it controls.<p>[1]<a href="http://svn.python.org/projects/python/trunk/Misc/README.valgrind" rel="nofollow">http:&#x2F;&#x2F;svn.python.org&#x2F;projects&#x2F;python&#x2F;trunk&#x2F;Misc&#x2F;README.valg...</a>
crispweedover 10 years ago
Something in between traditional bit vectors and sparse sets is described here:<p><a href="http://upcoder.com/9/fast-resettable-flag-vector/" rel="nofollow">http:&#x2F;&#x2F;upcoder.com&#x2F;9&#x2F;fast-resettable-flag-vector&#x2F;</a><p>This is designed for a fast clear, but doesn&#x27;t actually have constant time clear, it&#x27;s just O(n) clear with very small (amortized) constant. It&#x27;s a bit more cache friendly, though, I think, and gave us some nice speedups in practice.
mannykannotover 10 years ago
I think I have seen this method used in a data structure called something like a &#x27;B.* set&#x27; or &#x27;B.* index&#x27;, but I can&#x27;t remember the exact name. Does anyone have a clue as to what I am (mis)remembering?<p>Update: I remembered that the algorithm had something to do with checking if an item is not in a set, which quickly led me to Bloom Filter - not particularly similar, as it turns out.
bltover 10 years ago
Ahhhh, I love hacks like this :) But it is super branchy; I would definitely profile before assuming it&#x27;s an improvement.
im3w1lover 10 years ago
Reading from uninitialized memory in C seems to be a bad idea:<p><a href="http://blog.frama-c.com/index.php?post/2013/03/13/indeterminate-undefined" rel="nofollow">http:&#x2F;&#x2F;blog.frama-c.com&#x2F;index.php?post&#x2F;2013&#x2F;03&#x2F;13&#x2F;indetermin...</a>
评论 #8711582 未加载
评论 #8711674 未加载
评论 #8711655 未加载
评论 #8711932 未加载