So I was looking for a concrete example of dynamic memory allocation for game engine design, as the book "Game Engine Architecture" by Jason Gregory goes into a little detail about how allocating memory with 1 malloc() usage and then filling it with data instead of overusing malloc() which would slow down the entire engine. I came across this full explanation with source code examples:
My question lies in the 2nd portion of the topic of the aligned allocation portion. He is using reinterpret_cast(address), but I get an error by not having "<type-name-here>" before the "(address)". Is it supposed to be "reinterpret_cast<u8>(address)"? And is "<uint8_t>" the same thing, because I couldn't find the header file where u8 was defined.
So the code would look like this:
inline void* alignForward(void* address, uint8_t alignment)
{
return (void*)( ( reinterpret_cast<uint8_t>(address) + static_cast<uint8_t>(alignment-1)) & static_cast<uint8_t>(~(alignment-1)) );
}
What exactly is "reinterpret_cast<u8>(address)" doing? And the same for static_cast? I've never used those keywords before. Thank you for any help that can be provided
↧