예제 #1
0
void tommy_arrayblk_grow(tommy_arrayblk* array, unsigned size)
{
	unsigned block_max = (size + TOMMY_ARRAYBLK_SIZE - 1) / TOMMY_ARRAYBLK_SIZE;
	unsigned block_mac = tommy_array_size(&array->block);

	if (block_mac < block_max) {
		/* grow the block array */
		tommy_array_grow(&array->block, block_max);

		/* allocate new blocks */
		while (block_mac < block_max) {
			void* ptr = tommy_malloc(TOMMY_ARRAYBLK_SIZE * sizeof(void*));

			/* initializes it with zeros */
			memset(ptr, 0, TOMMY_ARRAYBLK_SIZE * sizeof(void*));

			/* set the new block */
			tommy_array_set(&array->block, block_mac, ptr);

			++block_mac;
		}
	}

	if (array->size < size)
		array->size = size;
}
예제 #2
0
파일: check.c 프로젝트: door/site_blocker
void test_array(void)
{
	tommy_array array;
	unsigned i;

	tommy_array_init(&array);

	START("array init");
	for(i=0;i<MAX*100;++i) {
		tommy_array_grow(&array, i + 1);
		if (tommy_array_get(&array, i) != 0)
			abort();
	}
	STOP();

	START("array set");
	for(i=0;i<MAX*100;++i) {
		tommy_array_set(&array, i, (void*)i);
	}
	STOP();

	START("array get");
	for(i=0;i<MAX*100;++i) {
		if (tommy_array_get(&array, i) != (void*)i)
			abort();
	}
	STOP();

	tommy_array_done(&array);
}
예제 #3
0
cr_cache_t *crcache_init (void) {
  cr_cache_t *cache;
  tommy_array *array;

  cache = calloc (1,sizeof (cr_cache_t));
  array = calloc (1,sizeof (tommy_array));

  tommy_array_init (array);

  cache->crates = array;
  cache->alloc_exp = TOMMY_ARRAY_BIT;
  cache->read = crcache_read;
  cache->write = crcache_write;
  cache->free = crcache_free;

  tommy_array_grow (cache->crates,pow (2,cache->alloc_exp));

  return cache;
}
예제 #4
0
static void crcache_grow (cr_cache_t *cache) {
  cache->alloc_exp++;
  tommy_array_grow (cache->crates,pow (2,cache->alloc_exp));
  return;
}