News for hackers. Stuff that matters.
Re:Ask HN: Favorite pointer tricks in C? by jbeda on Sunday November 21, 2010 @12:09AM (#1926367)
A trick to save memory:

If you have a struct/class with a lot of members that are usually set to zero or some other initial value, you can store them in a "lookaside" structure that is hung off a global hash table with the pointer of the original object as the hashtable key. You can then use a bitfield to keep track of which members actually have interesting data.

So -- accessing the member would look something like this:

  int MyClass::get_foo() {
    if (foo_set_)
      return global_lookaside[this].foo;
    return 0;
  }

There are no comments on this comment yet.