public static PtrBuffer *Create(int capacity = START_CAPACITY, int multiplier = MULTIPLIER) { Ion.assert(multiplier >= MULTIPLIER); Ion.assert(capacity > 0); var b = (PtrBuffer *)Ion.xmalloc(sizeof(PtrBuffer)); b->_capacity = capacity; b->_multiplier = multiplier; b->count = 0; b->buf_byte_size = capacity * Ion.PTR_SIZE; b->_begin = (void **)Ion.xmalloc(b->buf_byte_size); b->_top = b->_begin; b->_end = b->_begin + b->buf_byte_size; return(b); }
public static Buffer <T> Create(int capacity = START_CAPACITY, int multiplier = MULTIPLIER) { Ion.assert(capacity >= START_CAPACITY); Ion.assert(multiplier > 1); var b = new Buffer <T> { item_size = sizeof(T), _capacity = capacity, _multiplier = multiplier, count = 0 }; b.buffer_size = b._capacity * b.item_size; b._begin = (T *)Ion.xmalloc(b.buffer_size); b._top = b._begin; return(b); }
void map_grow(ulong new_cap) { new_cap = Ion.CLAMP_MIN(new_cap, 16); var new_map = new Map { keys = (ulong *)Ion.xcalloc((int)new_cap, sizeof(ulong)), vals = (ulong *)(void **)Ion.xmalloc((int)new_cap * sizeof(ulong)), cap = new_cap }; for (ulong i = 0; i < cap; i++) { if (keys[i] != 0) { new_map.map_put_uint64_from_uint64(keys[i], vals[i]); } } Ion.xfree(keys); Ion.xfree(vals); this = new_map; }