Esempio n. 1
0
void		*malloc(size_t size)
{
	void	*ptr;

	size = 0 ? 1 : size;
	if (!g_map.tiny && !g_map.small && !g_map.large)
		init_glob();
	if (size + sizeof(t_header) > g_map.max_size || size > g_map.max_size)
		return (NULL);
	size += sizeof(t_block);
	if (size - sizeof(t_block) <= g_map.size_tiny)
	{
		if (!g_map.tiny && new_map(g_map.size_tiny, &g_map.tiny, NULL) < 0)
			return (NULL);
		ptr = find_free_space(g_map.size_tiny, size, &g_map.tiny);
	}
	else if (size - sizeof(t_block) <= g_map.size_small)
	{
		if (!g_map.small && new_map(g_map.size_small, &g_map.small, NULL) < 0)
			return (NULL);
		ptr = find_free_space(g_map.size_small, size, &g_map.small);
	}
	else
		ptr = large_alloc(size, &g_map.large);
	if (ptr)
		ptr = (void *)ptr + sizeof(t_block);
	return (ptr);
}
Esempio n. 2
0
void *nit_alloc(size_t s0)
{
	switch (gc_option) {
#ifdef WITH_LIBGC
	case gc_opt_boehm: return GC_MALLOC(s0);
#endif
	case gc_opt_malloc: return calloc(1, s0);
	case gc_opt_large:
	default: return large_alloc(s0);
	}
}
Esempio n. 3
0
void *cgc_malloc_alloc(malloc_t *heap, cgc_size_t n)
{
    void *ptr;

    if (n > MAX_SIZE)
        return NULL;

    n = ALIGNED(n, 4);

    if (n < TINY_SIZE)
        ptr = tiny_alloc(heap, TINY_SIZE);
    else if (n < SMALL_SIZE)
        ptr = tiny_alloc(heap, n);
    else if (n < LARGE_SIZE)
        ptr = small_alloc(heap, n);
    else
        ptr = large_alloc(heap, n);

    return ptr;
}