Created
December 1, 2013 07:03
-
-
Save zougloub/7729405 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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