With CXXFLAGS='-fsanitize=undefined' GCC complains about unaligned access:
if custom allocator is used to allocate structs or other alignment-sensitive
things, then it must take care of the alignment (for example, add padding
to all unaligned blocks of memory which it allocates).
class tcpool_t
{
- typedef slab_allocator_t<~0u, 4096> alc_t;
+ typedef slab_allocator_t<~0u, 4096, sizeof(void*)> alc_t;
typedef lookup_t<const tcmd_t*> index_t;
alc_t alc;
struct RE
{
- typedef slab_allocator_t<~0u, 4096> alc_t;
+ typedef slab_allocator_t<~0u, 4096, sizeof(void*)> alc_t;
enum type_t {NIL, SYM, ALT, CAT, ITER, TAG} type;
union {
const Range *sym;
* Works ~20 times faster, than linux's glibc allocator :]
*/
template<uint32_t MAXIMUM_INLINE = 4 * 1024,
- uint32_t SLAB_SIZE = 1024 * 1024>
+ uint32_t SLAB_SIZE = 1024 * 1024,
+ size_t ALIGN = 1>
class slab_allocator_t
{
typedef std::vector<char*> slabs_t;
{
char *result;
+ /* alignment */
+ size += ALIGN - size % ALIGN;
+
/* very large objects */
if (size > MAXIMUM_INLINE) {
result = static_cast<char*>(malloc(size));