Beispiel #1
0
void		*realloc_small_tiny(t_page_list *lst, void *ptr, size_t len)
{
	size_t	i;
	void	*addr;

	if (len <= get_block_size(lst->page.type))
	{
		MALLOC_UNLOCK();
		return (return_enomem(ptr));
	}
	if (!(addr = create_new_block(get_block_type(len), len)))
	{
		MALLOC_UNLOCK();
		return (return_enomem(NULL));
	}
	i = 0;
	while (i < len && i < lst->page.len - sizeof(*lst))
	{
		((unsigned char*)addr)[i] = ((unsigned char*)ptr)[i];
		i++;
	}
	free(ptr);
	MALLOC_UNLOCK();
	return (return_enomem(addr));
}
Beispiel #2
0
 void* mpool::alloc(size_t n) {
     if(n>mpool_default_size){
         return 0;
     }
     size_t left = current->end - current->last;
     if(n>left){
         create_new_block();
     }
     char* m = current->last;
     current->last += n;
     return m;
 }
Beispiel #3
0
void		*realloc_large(t_page_list *lst, void *ptr, size_t len)
{
	size_t	i;
	void	*addr;

	if (!(addr = create_new_block(LARGE, len)))
	{
		MALLOC_UNLOCK();
		return (return_enomem(NULL));
	}
	i = 0;
	while (i < len && i < lst->page.len - sizeof(*lst))
	{
		((unsigned char*)addr)[i] = ((unsigned char*)ptr)[i];
		i++;
	}
	remove_page(lst);
	munmap(lst, lst->page.len);
	MALLOC_UNLOCK();
	return (return_enomem(addr));
}