-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem.h
83 lines (74 loc) · 2.94 KB
/
mem.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* libslack - https://libslack.org
*
* Copyright (C) 1999-2004, 2010, 2020-2023 raf <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*
* 20230824 raf <[email protected]>
*/
#ifndef LIBSLACK_MEM_H
#define LIBSLACK_MEM_H
#include <stdlib.h>
#include <slack/hdr.h>
#include <slack/locker.h>
#ifndef null
#define null NULL
#endif
#ifndef nul
#define nul '\0'
#endif
typedef struct Pool Pool;
_begin_decls
#define mem_new(type) malloc(sizeof(type))
#define mem_create(size, type) malloc((size) * sizeof(type))
#define mem_resize(mem, size) mem_resize_fn((void **)(mem), (size) * sizeof(**(mem)))
void *mem_resize_fn(void **mem, size_t size);
#define mem_release(mem) free(mem)
void *mem_destroy(void **mem);
#define mem_destroy(mem) (mem_destroy)((void **)(mem))
void *mem_create_secure(size_t size);
void mem_release_secure(void *mem);
void *mem_destroy_secure(void **mem);
#define mem_destroy_secure(mem) (mem_destroy_secure)((void **)(mem))
char *mem_strdup(const char *str);
#define mem_create2d(i, j, type) ((type **)mem_create_space(sizeof(type), (i), (j), 0))
#define mem_create3d(i, j, k, type) ((type ***)mem_create_space(sizeof(type), (i), (j), (k), 0))
#define mem_create4d(i, j, k, l, type) ((type ****)mem_create_space(sizeof(type), (i), (j), (k), (l), 0))
void *mem_create_space(size_t size, ...);
size_t mem_space_start(size_t size, ...);
#define mem_release2d(space) mem_release_space(space)
#define mem_release3d(space) mem_release_space(space)
#define mem_release4d(space) mem_release_space(space)
#define mem_release_space(space) mem_release(space)
#define mem_destroy2d(space) mem_destroy_space(space)
#define mem_destroy3d(space) mem_destroy_space(space)
#define mem_destroy4d(space) mem_destroy_space(space)
#define mem_destroy_space(space) mem_destroy(space)
Pool *pool_create(size_t size);
Pool *pool_create_with_locker(Locker *locker, size_t size);
void pool_release(Pool *pool);
void *pool_destroy(Pool **pool);
Pool *pool_create_secure(size_t size);
Pool *pool_create_secure_with_locker(Locker *locker, size_t size);
void pool_release_secure(Pool *pool);
void *pool_destroy_secure(Pool **pool);
void pool_clear_secure(Pool *pool);
#define pool_new(pool, type) pool_alloc((pool), sizeof(type))
#define pool_newsz(pool, size, type) pool_alloc((pool), (size) * sizeof(type))
void *pool_alloc(Pool *pool, size_t size);
void pool_clear(Pool *pool);
_end_decls
#endif
/* vi:set ts=4 sw=4: */