QSize 与使用 2 Int 有常量的比较

发布于 2024-12-22 11:42:05 字数 304 浏览 3 评论 0原文

我正在做一个需要 2 个常量的项目:

Minimum Size of application (Width, Height) 
Initial Size of application (Width, Height)

我想知道哪一个会消耗更少的内存:

1- 一个 QSize(该变量将包含初始宽度和 高度和该 QSize 的最小缩放比例)

2-4个整数(MinH、MinW、IniH、IniW)

感谢您的建议!

I'm doing a project needing 2 constants:

Minimum Size of application (Width, Height) 
Initial Size of application (Width, Height)

I would like to know which would take less memory cossumption to do:

1- One QSize (which the variable would contain the initial width and
height and the minimum being scaled of this QSize)

2- 4 ints (MinH, MinW, IniH, IniW)

Thanks for your suggestions !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

躲猫猫 2024-12-29 11:42:05

代码:

std::cout << "QSize: " << sizeof(QSize) << std::endl;

输出:

QSize: 8

你计算一下。

Code:

std::cout << "QSize: " << sizeof(QSize) << std::endl;

Outputs:

QSize: 8

you do the math.

救赎№ 2024-12-29 11:42:05

不确定“此 QSize 的最小缩放比例”是什么意思。

QSize 本质上只是一个包装 2 个 int 的结构体,因此它使用与 2 个 int 相同的内存量。

我非常怀疑任何您需要担心 4 个整数的内存占用的平台的维度都会大于 64k,因此,如果内存确实是一个问题,您应该考虑使用 4 个无符号短整型而不是 4 个整数,这将使用一半的记忆。

Not sure what you mean by "the minimum being scaled of this QSize".

QSize is essentially just a struct wrapping 2 ints, so it uses the same amount of memory as 2 ints.

I doubt very much that any platform where you'd need to worry about the memory footprint of 4 integers would have dimensions greater than 64k, so if memory is really an issue you should consider using 4 unsigned shorts instead of 4 ints, which would use half the memory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文