Better HN
topnewbestaskshowjobs
Log inSign up

kkdwivedi

2 karma · joined Feb 28, 2019 (7y ago) · 2 submissions

Submissions

comment 6y ago · link · parent

Right, totally depends on what you're doing. My example is not a good fit for intrusive use cases.

comment 6y ago · link · parent

Another option is a struct with a FAM at the end.

  typedef struct {
      size_t len;
      uint8_t data[];
  } ByteBuf;
Then, allocation becomes

  ByteBuf *b = malloc(sizeof(*b) + sizeof(uint8_t) * array_size);
  b->len = array_size;
and data is no longer a pointer.