我是否需要对齐的内存存储来加载文件?

Do I need an aligned memory storage to load a file?

我需要将使用 fstream 从文件加载到内存的字体传递到 FT library function。它需要是基本字符指针。现在经过一些阅读我怀疑我是否需要分配实际对齐的内存存储来加载文件。我认为当一个字体文件被创建时,它有不同类型的数据,如果文件被加载到一个未对齐的 char 数组中(也就是说,它从未对齐的基地址开始)可能会有一些问题(至少,性能问题)读取数据时。或者也许我错了,一切都很好。

经过进一步调查,我发现我不需要明确对齐。来自关于分配函数的标准 [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..

来自 cppreference.com 关于 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.

因此编译器已经处理了对齐。