LispBM
lbm_defrag_mem.h
Go to the documentation of this file.
1 /*
2  Copyright 2024 Joel Svensson svenssonjoel@yahoo.se
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef LBM_DEFRAG_MEM_H_
19 #define LBM_DEFRAG_MEM_H_
20 
21 #include <heap.h>
22 #include <stdint.h>
23 
25 extern void lbm_defrag_mem_destroy(lbm_uint *ptr);
26 extern lbm_value lbm_defrag_mem_alloc(lbm_uint *defrag_mem, lbm_uint nbytes);
27 extern void lbm_defrag_mem_free(lbm_uint* data);
28 
29 static inline bool lbm_defrag_mem_valid(lbm_value arr) {
30  return !(lbm_is_symbol_nil(lbm_car(arr)));
31 }
32 
33 static inline bool lbm_is_defrag_mem(lbm_value x) {
34  lbm_type t = lbm_type_of(x);
35  return ((t == LBM_TYPE_DEFRAG_MEM) && lbm_defrag_mem_valid(x)) ;
36 }
37 
38 
39 #endif
lbm_defrag_mem_destroy
void lbm_defrag_mem_destroy(lbm_uint *ptr)
Definition: lbm_defrag_mem.c:84
lbm_car
lbm_value lbm_car(lbm_value cons)
Definition: heap.c:902
lbm_defrag_mem_alloc
lbm_value lbm_defrag_mem_alloc(lbm_uint *defrag_mem, lbm_uint nbytes)
Definition: lbm_defrag_mem.c:220
lbm_defrag_mem_valid
static bool lbm_defrag_mem_valid(lbm_value arr)
Definition: lbm_defrag_mem.h:29
lbm_uint
uint32_t lbm_uint
Definition: lbm_types.h:48
lbm_is_symbol_nil
static bool lbm_is_symbol_nil(lbm_value exp)
Definition: heap.h:834
lbm_defrag_mem_create
lbm_value lbm_defrag_mem_create(lbm_uint nbytes)
Definition: lbm_defrag_mem.c:38
lbm_defrag_mem_free
void lbm_defrag_mem_free(lbm_uint *data)
Definition: lbm_defrag_mem.c:241
lbm_type_of
static lbm_type lbm_type_of(lbm_value x)
Definition: heap.h:663
lbm_value
uint32_t lbm_value
Definition: lbm_types.h:44
LBM_TYPE_DEFRAG_MEM
#define LBM_TYPE_DEFRAG_MEM
Definition: lbm_defines.h:58
lbm_is_defrag_mem
static bool lbm_is_defrag_mem(lbm_value x)
Definition: lbm_defrag_mem.h:33
lbm_type
uint32_t lbm_type
Definition: lbm_types.h:46
heap.h