@@ -66,8 +66,6 @@ static void umf_ba_create_global(void) {
66
66
67
67
// returns index of the allocation class for a given size
68
68
static int size_to_idx (size_t size ) {
69
- assert (size <= BASE_ALLOC .ac_sizes [NUM_ALLOCATION_CLASSES - 1 ]);
70
-
71
69
if (size <= BASE_ALLOC .ac_sizes [0 ]) {
72
70
return 0 ;
73
71
}
@@ -77,15 +75,14 @@ static int size_to_idx(size_t size) {
77
75
(int )(log2Utils (size ) + !isPowerOf2 - BASE_ALLOC .smallest_ac_size_log2 );
78
76
79
77
assert (index >= 0 );
80
- assert (index < NUM_ALLOCATION_CLASSES );
81
-
82
78
return index ;
83
79
}
84
80
85
81
void * umf_ba_global_alloc (size_t size ) {
86
82
util_init_once (& ba_is_initialized , umf_ba_create_global );
87
83
88
- if (size > BASE_ALLOC .ac_sizes [NUM_ALLOCATION_CLASSES - 1 ]) {
84
+ int ac_index = size_to_idx (size );
85
+ if (ac_index >= NUM_ALLOCATION_CLASSES ) {
89
86
#ifndef NDEBUG
90
87
fprintf (stderr ,
91
88
"base_alloc: allocation size larger than the biggest "
@@ -94,24 +91,16 @@ void *umf_ba_global_alloc(size_t size) {
94
91
return ba_os_alloc (size );
95
92
}
96
93
97
- int ac_index = size_to_idx (size );
98
- if (!BASE_ALLOC .ac [ac_index ]) {
99
- // if creating ac failed, fall back to os allocation
100
- fprintf (stderr , "base_alloc: allocation class not created. Falling "
101
- "back to OS memory allocation.\n" );
102
- return ba_os_alloc (size );
103
- }
104
-
105
94
return umf_ba_alloc (BASE_ALLOC .ac [ac_index ]);
106
95
}
107
96
108
97
void umf_ba_global_free (void * ptr , size_t size ) {
109
- if (size > BASE_ALLOC .ac_sizes [NUM_ALLOCATION_CLASSES - 1 ]) {
98
+ int ac_index = size_to_idx (size );
99
+ if (ac_index >= NUM_ALLOCATION_CLASSES ) {
110
100
ba_os_free (ptr , size );
111
101
return ;
112
102
}
113
103
114
- int ac_index = size_to_idx (size );
115
104
if (!BASE_ALLOC .ac [ac_index ]) {
116
105
// if creating ac failed, memory must have been allocated by os
117
106
ba_os_free (ptr , size );
0 commit comments