For the best experience on desktop, install the Chrome extension to track your reading on news.ycombinator.com
Hacker Newsnew | past | comments | ask | show | jobs | submit | history | esneider's commentsregister

I wrote that algorithm! A year later I found Hacker's delight, a wonderful book that had a much "faster" version of the same algorithm (less ops).

For anyone interested in this kind of things, you should go read that book. It actually is a delight.


Which algorithm are you referring to?


I'd guess the linked one at the anchor #NextBitPermutation.


Anchor has since been removed, so the gp comment will look odd from here on out.


Hierarchical memory allocations are a great concept. But Samba's talloc is kind of bloated, with all the reference counting, destructors and stuff.

Here is a simple, 200-line version of just the hierarchical allocator: https://github.com/esneider/talloc


Too simple ;)

  void * p;

  p = talloc(1, NULL);
  talloc_set_parent(p, p);
  tfree(p);


Yep, you can also do

  void *p;
  free(p);
  free(p);
Don't get me wrong, I get where you are going. But C philosophy is that libraries shouldn't do expensive checking to detect programmers' errors.


I'm not going anywhere. Double-free is a known pitfall. People watch for it and a lot of standard libraries have safeguards against it.

On the other hand tfree() hangs if a prior call to talloc_set_parent() is passed certain arguments. Just more ammunition to shoot one's own foot. (p, p) might be a degenerate case, but real code will create cyclic references. In such case blaming programmer is the least productive way to handle it.


Fair enough... I thought it would be more difficult/inefficient to check for cyclic hierarchies, but it wasn't.

Fixed! Thanks.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search:

HN For You