Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save compiler-errors/e6f295c075b450052169a4a797bf0cef to your computer and use it in GitHub Desktop.
Save compiler-errors/e6f295c075b450052169a4a797bf0cef to your computer and use it in GitHub Desktop.

So we've got our struct. Imagine augmenting it with a bool called mark:

struct Foo {
  bool mark;
  int data_size;
  char[] data;
}

So we can walk through the pool of Foos that begins at buffer and ends at end:

while (iter < end) {
  Foo *block = (Foo *)iter;
  printf(“Ive got a block of size %d. She is %s. She encodes: %s.”, 
         block->size, block->mark ? "marked" : "not marked", block->data);
  iter += sizeof(struct Foo) + block->size;
}

Imagine I wanted to compact this buffer, removing all the structs which have mark == false...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment