Skip to content

Instantly share code, notes, and snippets.

@zougloub
Created December 1, 2013 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zougloub/7729405 to your computer and use it in GitHub Desktop.
Save zougloub/7729405 to your computer and use it in GitHub Desktop.
// amd64
typedef unsigned long size_t;
void *tor_realloc(void *, size_t);
typedef struct smartlist_t {
void **list;
int num_used;
int capacity;
} smartlist_t;
void smartlist_ensure_capacity(smartlist_t *sl, int size) {
#define MAX_CAPACITY 16
if (size > sl->capacity) {
int higher = sl->capacity;
if ((size > MAX_CAPACITY/2)) {
higher = MAX_CAPACITY;
}
else {
while (size > higher)
higher *= 2;
}
sl->capacity = higher;
sl->list = tor_realloc(sl->list, sizeof(void*)*((size_t)sl->capacity));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment