mas-bandwidth / yojimbo

A network library for client/server games written in C++
BSD 3-Clause "New" or "Revised" License
2.45k stars 238 forks source link

Replaced tlsf_malloc() with tlsf_memalign(16) #168

Closed sherief closed 2 years ago

sherief commented 2 years ago

...since compilers like MSVC assume allocation functions return 16-bit alignment.

This causes issues with messages that have fields aligned (via __declspec() or alignas()) to 16-bytes, since the compiler assumes allocated structs will be placed on a 16-byte boundary, but tlsf_malloc() only guarantees an 8-byte alignment so a member declared inside a Yojimbo message with 16-byte alignment might end up at an 8-byte boundary.

This has a tiny cost of the occasional additional 8-bytes of waste per allocation, but in practice I've seen this to be within noise. Debugging an issue like this might be unobvious for non-senior engineers, so I think the cost is justified.

sherief commented 2 years ago

@gafferongames Any reasons this isn't being merged? It fixes actual production issues with yojimbo messages that contain member with alignas() requirements.