The 2024 Wheel Reinvention Jam is in 16 days. September 23-29, 2024. More info

Alignment Arena Allocator

Hi! I am reading a article by Ginger Bill
https://www.gingerbill.org/articl...memory-allocation-strategies-002/

in the article he describes how to implement a basic Arena Allocator. i thought the code was fairly straightforward, but I had a question about something he did.

1
2
3
4
5
6
7
8
#ifndef DEFAULT_ALIGNMENT
#define DEFAULT_ALIGNMENT (2*sizeof(void *))
#endif

// Because C doesn't have default parameters
void *arena_alloc(Arena *a, size_t size) {
	return arena_alloc_align(a, size, DEFAULT_ALIGNMENT);
}


as you can see he set DEFAULT_ALIGNMENT to 2 * sizeof(void *). I understand that Processors often operate best when things are aligned to their native Word Size, but why is it that GB chose to set the DEFAULT_ALIGNMENT to 2 * WORD_SIZE?

Edited by Draos on Reason: Initial post
If he is writing this only for x64 then this probably is because of SSE types. SSE has special instructions that work faster on some CPUs when memory is aligned to 16 bytes. 2*sizeof(void*) is 16 bytes.
makes sense to me. thanks Mārtiņš