-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_new_memarena.c
More file actions
37 lines (34 loc) · 1.35 KB
/
Copy pathft_new_memarena.c
File metadata and controls
37 lines (34 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_new_memarena.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jvarila <jvarila@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/21 12:09:51 by jvarila #+# #+# */
/* Updated: 2025/03/21 12:13:03 by jvarila ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* Creates new memarena struct with MEM_ARENA_SIZE bytes of heap memory.
* <p>
* Return NULL if malloc can't return heap memory.
*/
void *ft_new_memarena(void)
{
t_memarena *arena;
arena = malloc(sizeof(t_memarena));
if (!arena)
return (NULL);
arena->heap_memory = malloc(MEM_ARENA_SIZE);
if (!arena->heap_memory)
{
free(arena);
return (NULL);
}
arena->capacity = MEM_ARENA_SIZE;
arena->bytes_used = 0;
arena->next = NULL;
return (arena);
}