blob: c9c8407829e12fbb9356fcdf802cacac8957e2d4 (
plain)
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
84
85
86
|
#ifndef FC_SOLVE__ALLOC_H
#define FC_SOLVE__ALLOC_H
#ifdef __cplusplus
extern "C"
{
#endif
struct fcs_compact_allocator_struct
{
char * * packs;
int max_num_packs;
int num_packs;
char * max_ptr;
char * ptr;
char * rollback_ptr;
};
typedef struct fcs_compact_allocator_struct fcs_compact_allocator_t;
extern fcs_compact_allocator_t *
freecell_solver_compact_allocator_new(void);
extern void freecell_solver_compact_allocator_extend(
fcs_compact_allocator_t * allocator
);
#if 0
extern char *
freecell_solver_compact_allocator_alloc(
fcs_compact_allocator_t * allocator,
int how_much
);
#else
#define fcs_compact_alloc_into_var(result,allocator_orig,what_t) \
{ \
fcs_compact_allocator_t * allocator = (allocator_orig); \
if (allocator->max_ptr - allocator->ptr < sizeof(what_t)) \
{ \
freecell_solver_compact_allocator_extend(allocator); \
} \
allocator->rollback_ptr = allocator->ptr; \
allocator->ptr += ((sizeof(what_t))+(sizeof(char *)-((sizeof(what_t))&(sizeof(char *)-1)))); \
result = (what_t *)allocator->rollback_ptr; \
}
#define fcs_compact_alloc_typed_ptr_into_var(result, type_t, allocator_orig, how_much_orig) \
{ \
fcs_compact_allocator_t * allocator = (allocator_orig); \
int how_much = (how_much_orig); \
if (allocator->max_ptr - allocator->ptr < how_much) \
{ \
freecell_solver_compact_allocator_extend(allocator); \
} \
allocator->rollback_ptr = allocator->ptr; \
/* Round ptr to the next pointer boundary */ \
allocator->ptr += ((how_much)+((sizeof(char *)-((how_much)&(sizeof(char *)-1)))&(sizeof(char*)-1))); \
result = (type_t *)allocator->rollback_ptr; \
}
#endif
#if 0
extern void freecell_solver_compact_allocator_release(fcs_compact_allocator_t * allocator);
#else
#define fcs_compact_alloc_release(allocator) \
{ \
(allocator)->ptr = (allocator)->rollback_ptr; \
}
#endif
extern void freecell_solver_compact_allocator_finish(fcs_compact_allocator_t * allocator);
extern void freecell_solver_compact_allocator_foreach(
fcs_compact_allocator_t * allocator,
int data_width,
void (*ptr_function)(void *, void *),
void * context
);
#ifdef __cplusplus
};
#endif
#endif
|