Skip to content

Instantly share code, notes, and snippets.

@acdimalev
Created April 26, 2010 13:46
Show Gist options
  • Save acdimalev/379340 to your computer and use it in GitHub Desktop.
Save acdimalev/379340 to your computer and use it in GitHub Desktop.
int allocate(blocks *b) {
int i;
i = (b->index + 1) % b->size;
while (i != b->index) {
if (b->map[i] == 0) {
b->map[i] = 1;
b->index = i;
return i;
}
i = (i + 1) % b->size;
}
return -1;
}
void free(blocks *b, int i) {
b->map[i] = 0;
b->index = (i - 1) % b->size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment