使用类对象而不是 VirtualStringTree 中的记录是否有任何权衡?
Regarding: Delphi, VirtualStringTree - classes (objects) instead of records
Does the memory increases or something?
PS: I am using Delphi 2007.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用对象代替记录有两个缺点。首先,每个对象比包含相同数据的记录大 4 个字节。 (或者从 D2009 开始为 8 个字节。)
其次,必须创建和销毁对象;它不像唱片那样“就在那里”。但从另一个问题来看,看来你的记录无论如何都必须通过指针来引用,所以这没有太大区别。您仍然需要动态分配记录并稍后释放它们。
但是,如果您使用对象,您将获得很多额外的灵活性,尤其是使用继承和多态性的能力。额外的 4 个字节绝对值得。
There are two drawbacks to using objects instead of records. First, each object is 4 bytes larger than a record containing the same data would be. (Or 8 bytes, from D2009 on.)
Second, an object has to be created and destroyed; it's not "just there" the way a record is. But from the other question, it looks like your records have to be referred to through pointers anyway, so that's not much of a difference. You'd still have to dynamically allocate your records and free them later.
But if you use an object you gain a lot of extra flexibility, especially the ability to use inheritance and polymorphism. It's definitely worth the extra 4 bytes.