File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ typedef struct arena_block {
79
79
typedef struct {
80
80
arena_block_t * head ;
81
81
int total_bytes ; /* Track total allocation for profiling */
82
+ int block_size ; /* Default block size for new blocks */
82
83
} arena_t ;
83
84
84
85
/* string-based hash map definitions */
Original file line number Diff line number Diff line change @@ -144,6 +144,8 @@ arena_t *arena_init(int initial_capacity)
144
144
}
145
145
arena -> head = arena_block_create (initial_capacity );
146
146
arena -> total_bytes = initial_capacity ;
147
+ /* Use the initial capacity as the default block size for future growth. */
148
+ arena -> block_size = initial_capacity ;
147
149
return arena ;
148
150
}
149
151
@@ -166,9 +168,12 @@ void *arena_alloc(arena_t *arena, int size)
166
168
size = (size + PTR_SIZE - 1 ) & ~(PTR_SIZE - 1 );
167
169
168
170
if (!arena -> head || arena -> head -> offset + size > arena -> head -> capacity ) {
169
- /* Need a new block: choose capacity = max(DEFAULT_ARENA_SIZE, size) */
170
- int new_capacity =
171
- (size > DEFAULT_ARENA_SIZE ? size : DEFAULT_ARENA_SIZE );
171
+ /* Need a new block: choose capacity = max(DEFAULT_ARENA_SIZE,
172
+ * arena->block_size, size) */
173
+ int base =
174
+ (arena -> block_size > DEFAULT_ARENA_SIZE ? arena -> block_size
175
+ : DEFAULT_ARENA_SIZE );
176
+ int new_capacity = (size > base ? size : base );
172
177
arena_block_t * new_block = arena_block_create (new_capacity );
173
178
new_block -> next = arena -> head ;
174
179
arena -> head = new_block ;
You can’t perform that action at this time.
0 commit comments