tag:blogger.com,1999:blog-8082954141980125536.post3668767728352742358..comments2008-04-08T02:40:41.287-04:00Comments on research!rsc: Using Uninitialized Memory for Fun and Profitrschttp://www.blogger.com/profile/06357099531993534337noreply@blogger.comBlogger19125tag:blogger.com,1999:blog-8082954141980125536.post-19100552900323935542008-04-08T02:40:00.000-04:002008-04-08T02:40:00.000-04:002008-04-08T02:40:00.000-04:00At first I thought it's going to be a virtual memo...At first I thought it's going to be a virtual memory trick. But no.<BR/>Well, actually, it could be. This reminds me of copying garbage collectors which also trade more space usage for less time allocating, and the algorithms when stripped of all the complexity have the same gist as those in the article.Rklz2http://wikitravel.org/en/User:Rklz2noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-11316822048986494332008-03-16T23:46:00.000-04:002008-03-16T23:46:00.000-04:002008-03-16T23:46:00.000-04:00Actually, I'm wrong. It's the declaration for ele...Actually, I'm wrong. It's the declaration for elements in sparse[] that must be unsigned. Bah.Danhttp://www.blogger.com/profile/03600762409582805750noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-20919980162156939442008-03-16T14:51:00.000-04:002008-03-16T14:51:00.000-04:002008-03-16T14:51:00.000-04:00@rsc i can be unsigned all day -- it's n that must...@rsc i can be unsigned all day -- it's n that must be unsigned :) The problem is when you dereference sparse[i]. If that value happens to be greater than MAXINT, it'll miss your n<0 check and Read AV.<BR/><BR/>I think it's a reasonable presumption that i will be generated in such a manner that it will fit into sparse[]. But you're making a post about how you can handle arbitrary values in memory -- you fail on half the values right now :)Danhttp://www.blogger.com/profile/03600762409582805750noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-38108294723586382812008-03-16T12:39:00.000-04:002008-03-16T12:39:00.000-04:002008-03-16T12:39:00.000-04:00@mobius: Yes. But a set is a data structure that ...@mobius: Yes. But a set is a data structure that only stores each element once, so that's okay. Or if you adapt it to do what the exercises asked, dense contains the list of vector indices that have been initialized with data. Either way, it's not a real restriction that the elements of dense be unique.rschttp://www.blogger.com/profile/09576271159839887762noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-40147418467260003402008-03-16T12:27:00.000-04:002008-03-16T12:27:00.000-04:002008-03-16T12:27:00.000-04:00Don't the elements of dense[] have to be unique in...Don't the elements of dense[] have to be unique integers for this to work? IMobiushttp://www.blogger.com/profile/11319149283079163004noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-49467945523590194862008-03-16T10:30:00.000-04:002008-03-16T10:30:00.000-04:002008-03-16T10:30:00.000-04:00Very cool. I will use this some day.Very cool. I will use this some day.datatypehttp://www.blogger.com/profile/01013093458246712927noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-77942566263469242382008-03-16T08:04:00.000-04:002008-03-16T08:04:00.000-04:002008-03-16T08:04:00.000-04:00@dan: Yes: i is unsigned, and in general add-membe...@dan: Yes: i is unsigned, and in general add-member needs to check whether the number is already there and all the routines should check i against the size of sparse. <BR/><BR/>I was trying to keep the presentation simple. The paper has all the gory details.rschttp://www.blogger.com/profile/09576271159839887762noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-34024435942290137982008-03-16T01:44:00.000-04:002008-03-16T01:44:00.000-04:002008-03-16T01:44:00.000-04:00Hey Russ,Came across this blog through a random li...Hey Russ,<BR/>Came across this blog through a random link. Then I was like... hey, I know this guy! <BR/><BR/>Great blog. I've bookmarked it. Hope you're doing well.<BR/><BR/>AJsplaghttp://www.blogger.com/profile/17506797414755089967noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-3169907392129482012008-03-16T01:33:00.000-04:002008-03-16T01:33:00.000-04:002008-03-16T01:33:00.000-04:0010 print "my brain hurts"20 goto 1010 print "my brain hurts"<BR/>20 goto 10Timothy Barrington-Smythehttp://www.blogger.com/profile/14714296623514958258noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-35196045399930088742008-03-16T01:29:00.000-04:002008-03-16T01:29:00.000-04:002008-03-16T01:29:00.000-04:00drew, Check that n>0 :)drew,<BR/><BR/> Check that n>0 :)Danhttp://www.blogger.com/profile/03600762409582805750noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-64888974293356956062008-03-16T01:28:00.000-04:002008-03-16T01:28:00.000-04:002008-03-16T01:28:00.000-04:00Besides crashing, in the case where sparse[i] is l...Besides crashing, in the case where sparse[i] is less than 0, then dense[sparse[i]] is <B>also</B> uninitialized memory. So, if dense[sparse[i]] <B>happens</B> to contain i, then you'll get a false positive for set membership.<BR/><BR/>(And, of course, I assume that i is constrained to be less than the size of the region malloc'd to sparse)Danhttp://www.blogger.com/profile/03600762409582805750noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-68333599867822186822008-03-16T00:30:00.000-04:002008-03-16T00:30:00.000-04:002008-03-16T00:30:00.000-04:00Took a look at this from a security perspective, s...Took a look at this from a security perspective, since at first glance, I thought I was looking at another instance of someone thinking uninitialized RAM contains random data. Actually, this works, and is pretty cool! Here's how it looks, from another lens. The canonical, trusted "array" is the dense array. However, this is potentially slow to access. So, a second array is created, in which the value in the array is itself used as an index into the dense array. Now, the uninitialized memory could contain anything, but the value there will either refer back to the entry in the trusted dataset, or it will not.<BR/><BR/>One possible source of trouble is the fact that if the same i is added to the array twice, the second entry will blow away the first one in the sparse set, meaning you'll have a value in the dense set with no index entry pointing back to it. For certain scenarios, this could be a problem.<BR/><BR/>A much bigger issue, however, is that the integer isn't called out as needing to be unsigned :) If it isn't, the memory at sparse[i] could contain a number greater than MAXINT, which would be less than 0, and thus pass n<0 membership. Your system would (likely) crash.Danhttp://www.blogger.com/profile/03600762409582805750noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-56935647260812770522008-03-15T14:06:00.000-04:002008-03-15T14:06:00.000-04:002008-03-15T14:06:00.000-04:00@gruseom: The space cost is 2 words per potential ...@gruseom: The space cost is 2 words per potential entry (per universe member). I've changed the wording to be clearer, I hope. The contrast there is just supposed to be the 2 words vs 1 bit.rschttp://www.blogger.com/profile/09576271159839887762noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-39696891607468104442008-03-15T03:17:00.000-04:002008-03-15T03:17:00.000-04:002008-03-15T03:17:00.000-04:00Very cool. But is it correct to say that the space...Very cool. But is it correct to say that the space requirement is two words per element (by which I assume you mean 2*n)? What if one of the integers in the set is very large, wouldn't the sparse vector have to consume correspondingly large space?gruseomhttp://www.blogger.com/profile/01707010989897868629noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-50635946689696464232008-03-14T18:46:00.000-04:002008-03-14T18:46:00.000-04:002008-03-14T18:46:00.000-04:00There's also constant time remove (though a little...There's also constant time remove (though a <I>little</I> more work):<BR/><BR/>remove-member(i):<BR/> if not is-member(i): return<BR/> j = dense[n-1];<BR/> dense[sparse[i]] = j;<BR/> sparse[j] = sparse[i];<BR/> n = n - 1drewhttp://www.blogger.com/profile/09764774974069617487noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-49891744706787381492008-03-14T18:43:00.000-04:002008-03-14T18:43:00.000-04:002008-03-14T18:43:00.000-04:00@valhallasw: Thanks for pointing that out. Added ...@valhallasw: Thanks for pointing that out. Added some CSS magic to make the pre-blocks wrap.rschttp://www.blogger.com/profile/09576271159839887762noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-81052283036333747732008-03-14T18:13:00.000-04:002008-03-14T18:13:00.000-04:002008-03-14T18:13:00.000-04:00Doh. The pre-block cuts of anything that comes too...Doh. The pre-block cuts of anything that comes too far to the right, so the ==i didn't show up. Never knew pre-blocks within a div could be this evil :)valhallaswhttp://www.blogger.com/profile/10803977239416503120noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-36144653029147773252008-03-14T16:50:00.000-04:002008-03-14T16:50:00.000-04:002008-03-14T16:50:00.000-04:00@valhallasw: It already saiddense[sparse[i]] = i;...@valhallasw: It already said<BR/>dense[sparse[i]] = i; I've changed = to == so the pseudo-code is more like C.rschttp://www.blogger.com/profile/09576271159839887762noreply@blogger.comtag:blogger.com,1999:blog-8082954141980125536.post-11768227023940761552008-03-14T15:58:00.000-04:002008-03-14T15:58:00.000-04:002008-03-14T15:58:00.000-04:00is-member(i): return sparse[i] < n && dense[spa...is-member(i):<BR/> return sparse[i] < n && dense[sparse[i]]<BR/><BR/>Shouldn't this be<BR/> return sparse[i] < n && dense[sparse[i]]==i<BR/>, as dense can contain null elements. Obviously this only fails with a false=0 representation.valhallaswhttp://www.blogger.com/profile/10803977239416503120noreply@blogger.com