News for hackers. Stuff that matters.
Re:Ask HN: Favorite pointer tricks in C? by bbulkow on Saturday November 20, 2010 @08:04PM (#1925864)
This avoids allocation and is safe (the cost of two extra compares is low because they'll branch the same way all the time, so you'll get branch prediction power)

  char *bufp;
  uint8_t buf[1024];
  if (need_sz >= 1024)
    bufp = malloc(need_sz);
  else
    bufp = buf;
  ....
  if (bufp != buf) free(bufp);

There are no comments on this comment yet.