【发布时间】:2018-06-08 00:15:29
【问题描述】:
我正在使用 FlatBuffers (C++) 来存储有关文件的元数据信息。这包括 EXIF、IPTC、GPS 和各种其他元数据值。
在我当前的模式中,我有一个相当规范化的定义,上面列出的每个组都有自己的表。根表只包含每个子表的属性。
基本示例:
table GPSProperties {
latitude:double;
longitude:double;
}
table ContactProperties {
name:string;
email:string;
}
table EXIFProperties {
camera:string;
lens:string;
gps:GPSProperties;
}
table IPTCProperties {
city:string;
country:string;
contact:ContactProperties;
}
table Registry {
exifProperties:EXIFProperties;
iptcProperties:IPTCProperties;
}
root_type Registry;
这可行,但是构建缓冲区时的嵌套限制开始使代码变得非常混乱。同样,将属性分解为单独的表只是为了在架构中清晰。
我正在考虑将整个架构“扁平化”到一个表中,但我想知道这样做是否会影响性能或内存。这个单一的表可能有几百个字段,但大多数都是空的。
建议:
table Registry {
exif_camera:string;
exif_lens:string;
exif_gps_latitude:double;
exif_gps_longitude:double;
iptc_city:string;
iptc_country:string;
iptc_contact_name:string;
iptc_contact_email:string;
}
root_type Registry;
由于未设置或设置为其默认值的属性不会占用任何内存,我倾向于相信扁平化架构可能不会有问题。但我不确定。
(请注意,性能是我最关心的问题,其次是内存使用情况。规范化模式的性能非常好,但我认为扁平化模式确实有助于我清理代码库。)
【问题讨论】:
标签: c++ flatbuffers