【发布时间】:2010-11-04 08:47:21
【问题描述】:
我需要编写一种文件格式,将数据写入文件并可以读回。
它应该能够以相当快的速度读回数据,这应该涉及将一大块数据blit到std::vector中(因为它们的存储总是连续实现的)。
但是,在编写文件时,我不知道如何对整数和其他类型的对齐和大小进行约束。
这应该怎么做?我在 Q6600 (x86) 上的 buntu linux 上使用 gcc。
举个例子:
struct Vertex
{
float point [3];
float normal [3];
float texcoord [2];
}
稍后,数据存储在std::vector<Vertex> 中。我考虑过使用__attribute__ 并打包/对齐它,以便它在不同平台上更便携。
编辑: 我已经制定了规范,我打算使用它。最大的数据位是顶点和索引,因此它们将被读取为大块,例如(较大规范的一部分): VertexGroup 是一组共享一个特征的顶点。它们一次只能容纳一种材料,因此网格中应该包含许多材料。
<uint> thisid # Of this VertexGroup
<string> name
<uint> materialId # A material
<uint> vertexCount
for (vetexCount):
<3xfloat> point
<3xfloat> normal
<2xfloat> texcoord
<uint> triangleCount
for (triangleCount):
<3xuint> indices
【问题讨论】: