Exemple #1
0
void *drc_cache::alloc(size_t bytes)
{
	assert(bytes > 0);

	// pick first from the free list
	if (bytes < MAX_PERMANENT_ALLOC)
	{
		free_link **linkptr = &m_free[(bytes + CACHE_ALIGNMENT - 1) / CACHE_ALIGNMENT];
		free_link *link = *linkptr;
		if (link != NULL)
		{
			*linkptr = link->m_next;
			return link;
		}
	}

	// if no space, we just fail
	drccodeptr ptr = (drccodeptr)ALIGN_PTR_DOWN(m_end - bytes);
	if (m_top > ptr)
		return NULL;

	// otherwise update the end of the cache
	m_end = ptr;
	return ptr;
}
Exemple #2
0
void *drccache_memory_alloc(drccache *cache, size_t bytes)
{
	drccodeptr ptr;

	assert(bytes > 0);

	/* pick first from the free list */
	if (bytes < MAX_PERMANENT_ALLOC)
	{
		free_link **linkptr = &cache->free[(bytes + CACHE_ALIGNMENT - 1) / CACHE_ALIGNMENT];
		free_link *link = *linkptr;
		if (link != NULL)
		{
			*linkptr = link->next;
			return link;
		}
	}

	/* if no space, we just fail */
	ptr = (drccodeptr)ALIGN_PTR_DOWN(cache->end - bytes);
	if (cache->top > ptr)
		return NULL;

	/* otherwise update the end of the cache */
	cache->end = ptr;
	return ptr;
}