From 654ef30508d7465c49f8eb7d406513c10165b176 Mon Sep 17 00:00:00 2001 From: abxh Date: Thu, 5 Sep 2024 00:28:09 +0000 Subject: [PATCH] deploy: 8dea19875695c1d32195556a683d5852e2d275fe --- annotated.html | 6 +- arena_8h.html | 5 +- arena_8h_source.html | 297 ++++++------- classes.html | 9 +- doxygen_crawl.html | 6 +- examples_2arena_2char_array_8c-example.html | 10 +- examples_2arena_2fhashtable_8c-example.html | 12 +- examples_2list_2list_example_8c-example.html | 6 +- freelist_8h_source.html | 395 ++++++++++-------- search/all_6.js | 35 +- search/all_8.js | 7 +- search/classes_1.js | 5 +- search/classes_2.js | 2 +- search/classes_3.js | 2 +- search/classes_4.js | 4 + search/searchdata.js | 2 +- ...ist__allocation__header__type-members.html | 8 +- ...l__freelist__allocation__header__type.html | 14 +- 18 files changed, 444 insertions(+), 381 deletions(-) create mode 100644 search/classes_4.js rename structfreelist__allocation__header-members.html => structinternal__freelist__allocation__header__type-members.html (81%) rename structfreelist__allocation__header.html => structinternal__freelist__allocation__header__type.html (82%) diff --git a/annotated.html b/annotated.html index 260c1ba6..99497bbb 100644 --- a/annotated.html +++ b/annotated.html @@ -95,9 +95,9 @@  Cfpqueue_element_typeGenerated priority queue element struct type for a given VALUE_TYPE  Cfpqueue_typeGenerated priority queue struct type for a given VALUE_TYPE  Cfqueue_typeGenerated queue struct type for a VALUE_TYPE - Cfreelist_allocation_header - Cfreelist_type - Cfstack_typeGenerated stack struct type for a given VALUE_TYPE + Cfreelist_type + Cfstack_typeGenerated stack struct type for a given VALUE_TYPE + Cinternal_freelist_allocation_header_type  Clist_node_typeIntrusive list node structure  Crbtree_node_typeGenerated red-black tree node struct type for a given KEY_TYPE diff --git a/arena_8h.html b/arena_8h.html index dbb42bab..8e67aaa7 100644 --- a/arena_8h.html +++ b/arena_8h.html @@ -104,6 +104,7 @@ #include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <stdalign.h>

Go to the source code of this file.

@@ -115,7 +116,7 @@
- +

Macros

#define DEFAULT_ALIGNMENT   (2 * sizeof(void*))
#define DEFAULT_ALIGNMENT   (alignof(max_align_t))
 Default alignment when no alignment size is given.
 
@@ -151,7 +152,7 @@

- +
#define DEFAULT_ALIGNMENT   (2 * sizeof(void*))#define DEFAULT_ALIGNMENT   (alignof(max_align_t))
diff --git a/arena_8h_source.html b/arena_8h_source.html index efdf2c5e..fa48de9b 100644 --- a/arena_8h_source.html +++ b/arena_8h_source.html @@ -111,163 +111,164 @@
36#include <stdint.h>
37#include <stdlib.h>
38#include <string.h>
-
39
-
46#ifndef DEFAULT_ALIGNMENT
-
47#define DEFAULT_ALIGNMENT (2 * sizeof(void*))
-
48#endif
-
49
-
-
53typedef struct {
-
54 unsigned char* buffer_ptr;
- - - - +
39#include <stdalign.h>
+
40
+
47#ifndef DEFAULT_ALIGNMENT
+
48#define DEFAULT_ALIGNMENT (alignof(max_align_t))
+
49#endif
+
50
+
+
54typedef struct {
+
55 unsigned char* buffer_ptr;
+ + + +
-
59
-
61
-
62/* align pointer to the next alignment boundary */
-
63static inline uintptr_t internal_align_forward(const uintptr_t ptr, const size_t align);
-
64
-
66
-
-
74static inline void arena_init(arena_type* arena_ptr, const size_t n, unsigned char backing_buffer[n])
-
75{
-
76 assert(arena_ptr);
-
77 assert(backing_buffer);
-
78 arena_ptr->buffer_ptr = backing_buffer;
-
79 arena_ptr->buffer_length = n;
-
80 arena_ptr->current_offset = 0;
-
81 arena_ptr->previous_offset = 0;
-
82}
+
60
+
62
+
63/* align pointer to the next alignment boundary */
+
64static inline uintptr_t internal_align_forward(const uintptr_t ptr, const size_t align);
+
65
+
67
+
+
75static inline void arena_init(arena_type* arena_ptr, const size_t n, unsigned char backing_buffer[n])
+
76{
+
77 assert(arena_ptr);
+
78 assert(backing_buffer);
+
79 arena_ptr->buffer_ptr = backing_buffer;
+
80 arena_ptr->buffer_length = n;
+
81 arena_ptr->current_offset = 0;
+
82 arena_ptr->previous_offset = 0;
+
83}
-
83
-
-
89static inline void arena_deallocate_all(arena_type* arena_ptr)
-
90{
-
91 assert(arena_ptr);
-
92 arena_ptr->current_offset = 0;
-
93 arena_ptr->previous_offset = 0;
-
94}
+
84
+
+
90static inline void arena_deallocate_all(arena_type* arena_ptr)
+
91{
+
92 assert(arena_ptr);
+
93 arena_ptr->current_offset = 0;
+
94 arena_ptr->previous_offset = 0;
+
95}
-
95
-
-
105static inline void* arena_allocate_aligned(arena_type* arena_ptr, const size_t alignment, const size_t size)
-
106{
-
107 assert(arena_ptr);
-
108 // clang-format off
-
109
-
110 // Align `current_offset` forward to the specified alignment
-
111
-
112 const uintptr_t current_ptr =
-
113 + (uintptr_t) arena_ptr->buffer_ptr
-
114 + (uintptr_t) arena_ptr->current_offset;
-
115
-
116 const uintptr_t relative_offset =
-
117 + (uintptr_t) internal_align_forward(current_ptr, alignment)
-
118 - (uintptr_t) arena_ptr->buffer_ptr;
-
119
-
120 // clang-format on
-
121
-
122 // Check to see if the backing memory has space left
-
123 if (relative_offset + size <= arena_ptr->buffer_length) {
-
124
-
125 arena_ptr->previous_offset = relative_offset;
-
126 arena_ptr->current_offset = relative_offset + size;
-
127
-
128 void* ptr = (unsigned char*)&arena_ptr->buffer_ptr[relative_offset];
-
129 memset(ptr, 0, size); // zero memory by default
-
130
-
131 return ptr;
-
132 }
-
133 return NULL;
-
134}
+
96
+
+
106static inline void* arena_allocate_aligned(arena_type* arena_ptr, const size_t alignment, const size_t size)
+
107{
+
108 assert(arena_ptr);
+
109 // clang-format off
+
110
+
111 // Align `current_offset` forward to the specified alignment
+
112
+
113 const uintptr_t current_ptr =
+
114 + (uintptr_t) arena_ptr->buffer_ptr
+
115 + (uintptr_t) arena_ptr->current_offset;
+
116
+
117 const uintptr_t relative_offset =
+
118 + (uintptr_t) internal_align_forward(current_ptr, alignment)
+
119 - (uintptr_t) arena_ptr->buffer_ptr;
+
120
+
121 // clang-format on
+
122
+
123 // Check to see if the backing memory has space left
+
124 if (relative_offset + size <= arena_ptr->buffer_length) {
+
125
+
126 arena_ptr->previous_offset = relative_offset;
+
127 arena_ptr->current_offset = relative_offset + size;
+
128
+
129 void* ptr = (unsigned char*)&arena_ptr->buffer_ptr[relative_offset];
+
130 memset(ptr, 0, size); // zero memory by default
+
131
+
132 return ptr;
+
133 }
+
134 return NULL;
+
135}
-
135
-
-
144static inline void* arena_allocate(arena_type* arena_ptr, const size_t size)
-
145{
-
146 assert(arena_ptr);
-
147 return arena_allocate_aligned(arena_ptr, DEFAULT_ALIGNMENT, size);
-
148}
+
136
+
+
145static inline void* arena_allocate(arena_type* arena_ptr, const size_t size)
+
146{
+
147 assert(arena_ptr);
+
148 return arena_allocate_aligned(arena_ptr, DEFAULT_ALIGNMENT, size);
+
149}
-
149
-
-
161static inline void* arena_reallocate_aligned(arena_type* arena_ptr, void* old_memory_ptr, const size_t alignment,
-
162 const size_t old_size, const size_t new_size)
-
163{
-
164 assert(arena_ptr);
-
165 assert(is_pow2(alignment));
-
166
-
167 const unsigned char* old_mem_buf = (unsigned char*)old_memory_ptr;
-
168
-
169 if (old_mem_buf == NULL || old_size == 0) {
-
170 return arena_allocate_aligned(arena_ptr, alignment, new_size);
-
171 }
-
172 else if (!(arena_ptr->buffer_ptr <= old_mem_buf && old_mem_buf < arena_ptr->buffer_ptr + arena_ptr->buffer_length)) {
-
173 return NULL;
-
174 }
-
175
-
176 // optimization using previous_offset
-
177 if (arena_ptr->buffer_ptr + arena_ptr->previous_offset == old_mem_buf) {
-
178 arena_ptr->current_offset = arena_ptr->previous_offset + new_size;
-
179 if (new_size > old_size) {
-
180 memset(&arena_ptr->buffer_ptr[arena_ptr->current_offset], 0, new_size - old_size);
-
181 }
-
182 return old_memory_ptr;
-
183 }
-
184
-
185 const size_t copy_size = old_size < new_size ? old_size : new_size;
-
186
-
187 void* new_memory = arena_allocate_aligned(arena_ptr, alignment, new_size);
-
188
-
189 // Copy across old memory to the new memory
-
190 memmove(new_memory, old_mem_buf, copy_size);
-
191
-
192 return new_memory;
-
193}
+
150
+
+
162static inline void* arena_reallocate_aligned(arena_type* arena_ptr, void* old_memory_ptr, const size_t alignment,
+
163 const size_t old_size, const size_t new_size)
+
164{
+
165 assert(arena_ptr);
+
166 assert(is_pow2(alignment));
+
167
+
168 const unsigned char* old_mem_buf = (unsigned char*)old_memory_ptr;
+
169
+
170 if (old_mem_buf == NULL || old_size == 0) {
+
171 return arena_allocate_aligned(arena_ptr, alignment, new_size);
+
172 }
+
173 else if (!(arena_ptr->buffer_ptr <= old_mem_buf && old_mem_buf < arena_ptr->buffer_ptr + arena_ptr->buffer_length)) {
+
174 return NULL;
+
175 }
+
176
+
177 // optimization using previous_offset
+
178 if (arena_ptr->buffer_ptr + arena_ptr->previous_offset == old_mem_buf) {
+
179 arena_ptr->current_offset = arena_ptr->previous_offset + new_size;
+
180 if (new_size > old_size) {
+
181 memset(&arena_ptr->buffer_ptr[arena_ptr->current_offset], 0, new_size - old_size);
+
182 }
+
183 return old_memory_ptr;
+
184 }
+
185
+
186 const size_t copy_size = old_size < new_size ? old_size : new_size;
+
187
+
188 void* new_memory = arena_allocate_aligned(arena_ptr, alignment, new_size);
+
189
+
190 // Copy across old memory to the new memory
+
191 memmove(new_memory, old_mem_buf, copy_size);
+
192
+
193 return new_memory;
+
194}
-
194
-
-
205static inline void* arena_reallocate(arena_type* arena_ptr, void* old_memory_ptr, const size_t old_size, const size_t new_size)
-
206{
-
207 assert(arena_ptr);
-
208 return arena_reallocate_aligned(arena_ptr, old_memory_ptr, DEFAULT_ALIGNMENT, old_size, new_size);
-
209}
+
195
+
+
206static inline void* arena_reallocate(arena_type* arena_ptr, void* old_memory_ptr, const size_t old_size, const size_t new_size)
+
207{
+
208 assert(arena_ptr);
+
209 return arena_reallocate_aligned(arena_ptr, old_memory_ptr, DEFAULT_ALIGNMENT, old_size, new_size);
+
210}
-
210
-
212static inline uintptr_t internal_align_forward(const uintptr_t ptr, const size_t align)
-
213{
-
214 assert(is_pow2(align));
-
215
-
216 const uintptr_t p = ptr;
-
217 const uintptr_t a = (uintptr_t)align;
-
218 const uintptr_t r = p & (a - 1); // Same as (p % a) but faster as 'a' is a power of two
-
219
-
220 /*
-
221 for alignment 8:
-
222 alignment_padding = ... , 0, 7, 6, 5, 4, 3, 2, 1, 0, ...
-
223 /|\ /|\
-
224 (at alignment boundaries) | |
-
225 */
-
226 const uintptr_t alignment_padding = ((r != 0) ? 1 : 0) * (a - r);
-
227
-
228 return p + alignment_padding;
-
229}
-
#define DEFAULT_ALIGNMENT
Default alignment when no alignment size is given.
Definition arena.h:47
-
static void * arena_allocate(arena_type *arena_ptr, const size_t size)
Get the pointer to a chunk of the arena.
Definition arena.h:144
-
static void arena_init(arena_type *arena_ptr, const size_t n, unsigned char backing_buffer[n])
Initialize the arena.
Definition arena.h:74
-
static void arena_deallocate_all(arena_type *arena_ptr)
Deallocate all allocations in the arena.
Definition arena.h:89
-
static void * arena_reallocate(arena_type *arena_ptr, void *old_memory_ptr, const size_t old_size, const size_t new_size)
Reallocate a previously allocated chunk in the arena.
Definition arena.h:205
-
static void * arena_reallocate_aligned(arena_type *arena_ptr, void *old_memory_ptr, const size_t alignment, const size_t old_size, const size_t new_size)
Reallocate a previously allocated chunk in the arena. With aligment.
Definition arena.h:161
-
static void * arena_allocate_aligned(arena_type *arena_ptr, const size_t alignment, const size_t size)
Get the pointer to a chunk of the arena. With alignment.
Definition arena.h:105
+
211
+
213static inline uintptr_t internal_align_forward(const uintptr_t ptr, const size_t align)
+
214{
+
215 assert(is_pow2(align));
+
216
+
217 const uintptr_t p = ptr;
+
218 const uintptr_t a = (uintptr_t)align;
+
219 const uintptr_t r = p & (a - 1); // Same as (p % a) but faster as 'a' is a power of two
+
220
+
221 /*
+
222 for alignment 8:
+
223 alignment_padding = ... , 0, 7, 6, 5, 4, 3, 2, 1, 0, ...
+
224 /|\ /|\
+
225 (at alignment boundaries) | |
+
226 */
+
227 const uintptr_t alignment_padding = ((r != 0) ? 1 : 0) * (a - r);
+
228
+
229 return p + alignment_padding;
+
230}
+
#define DEFAULT_ALIGNMENT
Default alignment when no alignment size is given.
Definition arena.h:48
+
static void * arena_allocate(arena_type *arena_ptr, const size_t size)
Get the pointer to a chunk of the arena.
Definition arena.h:145
+
static void arena_init(arena_type *arena_ptr, const size_t n, unsigned char backing_buffer[n])
Initialize the arena.
Definition arena.h:75
+
static void arena_deallocate_all(arena_type *arena_ptr)
Deallocate all allocations in the arena.
Definition arena.h:90
+
static void * arena_reallocate(arena_type *arena_ptr, void *old_memory_ptr, const size_t old_size, const size_t new_size)
Reallocate a previously allocated chunk in the arena.
Definition arena.h:206
+
static void * arena_reallocate_aligned(arena_type *arena_ptr, void *old_memory_ptr, const size_t alignment, const size_t old_size, const size_t new_size)
Reallocate a previously allocated chunk in the arena. With aligment.
Definition arena.h:162
+
static void * arena_allocate_aligned(arena_type *arena_ptr, const size_t alignment, const size_t size)
Get the pointer to a chunk of the arena. With alignment.
Definition arena.h:106
Check if a number is a power of two.
static size_t is_pow2(const size_t x)
Check if a number is a power of two.
Definition is_pow2.h:33
-
Arena data struct.
Definition arena.h:53
-
size_t previous_offset
Previous offset describing space allocated in buffer.
Definition arena.h:56
-
size_t buffer_length
Underlying buffer length.
Definition arena.h:55
-
unsigned char * buffer_ptr
Underlying buffer pointer.
Definition arena.h:54
-
size_t current_offset
Current offset describing space allocated in buffer.
Definition arena.h:57
+
Arena data struct.
Definition arena.h:54
+
size_t previous_offset
Previous offset describing space allocated in buffer.
Definition arena.h:57
+
size_t buffer_length
Underlying buffer length.
Definition arena.h:56
+
unsigned char * buffer_ptr
Underlying buffer pointer.
Definition arena.h:55
+
size_t current_offset
Current offset describing space allocated in buffer.
Definition arena.h:58
-
A | F | L | R
+
A | F | I | L | R
diff --git a/doxygen_crawl.html b/doxygen_crawl.html index cb61a6f9..baab07a3 100644 --- a/doxygen_crawl.html +++ b/doxygen_crawl.html @@ -55,12 +55,12 @@ - - + + @@ -301,12 +301,12 @@ - + diff --git a/examples_2arena_2char_array_8c-example.html b/examples_2arena_2char_array_8c-example.html index 8e3f5427..9a7c8841 100644 --- a/examples_2arena_2char_array_8c-example.html +++ b/examples_2arena_2char_array_8c-example.html @@ -152,11 +152,11 @@
free(buf);
}
Arena allocator.
-
static void arena_init(arena_type *arena_ptr, const size_t n, unsigned char backing_buffer[n])
Initialize the arena.
Definition arena.h:74
-
static void arena_deallocate_all(arena_type *arena_ptr)
Deallocate all allocations in the arena.
Definition arena.h:89
-
static void * arena_reallocate_aligned(arena_type *arena_ptr, void *old_memory_ptr, const size_t alignment, const size_t old_size, const size_t new_size)
Reallocate a previously allocated chunk in the arena. With aligment.
Definition arena.h:161
-
static void * arena_allocate_aligned(arena_type *arena_ptr, const size_t alignment, const size_t size)
Get the pointer to a chunk of the arena. With alignment.
Definition arena.h:105
-
Arena data struct.
Definition arena.h:53
+
static void arena_init(arena_type *arena_ptr, const size_t n, unsigned char backing_buffer[n])
Initialize the arena.
Definition arena.h:75
+
static void arena_deallocate_all(arena_type *arena_ptr)
Deallocate all allocations in the arena.
Definition arena.h:90
+
static void * arena_reallocate_aligned(arena_type *arena_ptr, void *old_memory_ptr, const size_t alignment, const size_t old_size, const size_t new_size)
Reallocate a previously allocated chunk in the arena. With aligment.
Definition arena.h:162
+
static void * arena_allocate_aligned(arena_type *arena_ptr, const size_t alignment, const size_t size)
Get the pointer to a chunk of the arena. With alignment.
Definition arena.h:106
+
Arena data struct.
Definition arena.h:54