An aligned memory storage to load a file?

I need to pass a font that is loaded to the memory from a file with fstream into a FT library function. It needs to be the base char pointer. Now after some reading I am in doubt whether I need to allocate actually aligned memory storage to load the file. I think when a font file is created, it has data of different types in it, and if the file is loaded in an unaligned char array (that is, it begins at the unaligned base address) there can be some issues (at a minimum, performance issues) when reading the data. Or maybe I'm wrong and everything's fine. What do you think, what do you know?
Last edited on
its probably faster to try it in a little test program than to dig into the documents etc to verify.
often file data, even if binary, is pulled in as a char* or unsigned char* and fed forward to something that knows how to process it. See if it just wants the raw file data cast as a char* and if it works. If it fails, you will have to see what the routine's docs say are supposed to be in that char *, and how to get it into that format.
After further investigation I've found that I don't need to do aligning explicitly. From the standard about allocation functions [basic.stc.dynamic.allocation]:

The pointer returned shall be suitably aligned so that it can be converted to a pointer to any suitable complete object type..

From cppreference.com about std::max_align_t:

Pointers returned by allocation functions such as std::malloc are suitably aligned for any object, which means they are aligned at least as strictly as std::max_align_t.

Therefore aligning is already handled by the compiler.
Last edited on
Topic archived. No new replies allowed.