data_structures
array_new.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* array_new.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/16 23:19:33 by unite #+# #+# */
10 /* Updated: 2020/09/07 21:43:44 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "array.h"
15 
16 t_array *array_new(const t_type *type)
17 {
18  t_array *array;
19 
20  array = ds_xmalloc(sizeof(t_array));
21  array->arr = ds_xmalloc(sizeof(void *) * ARRAY_INIT_CAPACITY);
23  array->size = 0;
24  array->type = type;
25  return (array);
26 }
array.h
ds_xmalloc
void * ds_xmalloc(size_t size)
Replicates behaviour of malloc from libc, but fails on memory allocation errors.
Definition: ds_xmalloc.c:22
s_type
A full representation of a data type, used to achieve polymorphism in the implementation of data stru...
Definition: types.h:47
s_array::type
const t_type * type
The type of items in this array.
Definition: array.h:52
s_array::arr
void ** arr
The data.
Definition: array.h:51
s_array
A resizable array.
Definition: array.h:47
ARRAY_INIT_CAPACITY
#define ARRAY_INIT_CAPACITY
The initial capacity of an array.
Definition: array.h:24
s_array::capacity
size_t capacity
The capacity of this array.
Definition: array.h:50
s_array::size
size_t size
The number of items in this array.
Definition: array.h:49
array_new
t_array * array_new(const t_type *type)
Initializes a new empty array.
Definition: array_new.c:16