gpt4 book ai didi

c++ - 我需要 C++ 中的无限位掩​​码

转载 作者:行者123 更新时间:2023-11-28 01:37:05 25 4
gpt4 key购买 nike

可跳过上下文:我有一个模拟循环 ( using fixed update but variable rendering pattern ),它实例化 entities根据来自数百万组件(container state modifying pattern 的)数据库的用户输入和/或文件配置动态生成的类。

我已经实现了一个系统,自动...推导(某种逻辑单元/数学我不知道它的名字)并在用户输入时应用所需的组件/config 忽略了一个事实,即他们的一个选项需要额外的组件。

怎么会这样?许多组件是复杂的公式或模糊逻辑(门?)或其他复杂的科学推理,以一种可以操作我的模拟结构、它的对象、它的环境的方式编码,因此有时一个组件依赖于另一个组件,我需要'演绎算法/系统”,以便能够将该依赖传递给类构造函数。

我在决定存储这些“知识片段”的方式中使用了最大粒度,因为考虑到模拟的大小和计算强度以及单个实例的数量,我真的不能浪费任何内存,但现在我正在运行单个实例需要数千个,有时是数万个组件的问题,我需要实例的“创建映射”既保存又仍然绑定(bind)为私有(private)成员,这样我就可以: 1st - 知道我的推论在哪里引导构造函数实例,也许能够使用内存来减少构建时间;第二 - 在模拟过程中将更改注入(inject)实时实例¹。

What I think I need: I need a possibly infinite or at least very long bit-mask, so I can iterate the creation faster and let the final component-tree of my dynamically-constructed objects logged for future use.

Possible approaches, which I have no idea will work: 1st - Manually and sequentially store values for the bit flags in each RAM cell, using the RAM wafer as my bit-mask. 2nd - Breakdown the map into smaller bit-masks of known size(hard because the final number of components is unknown until the creation is done and decoupling the deduction is something which might even be impossible without refactoring the entire system). 3rd - Figure out a way to make an infinite bit-mask, or use some library that has implemented a really long integer(5.12e+11 or bigger).

我的代码是用 C++ 编写的,我的渲染和计算内核是 Vulkan。

我的客观问题:如何实现内存和计算效率高的任意长位掩码?

如果允许我提出一个奖励问题,假设我没有体系结构(软件和硬件)限制,实现这种位掩码的方法是什么?

¹ 我无法在模拟期间浏览对象的树,我也不能暂停模拟并等待浏览完成后再注入(inject)修改,我需要知道并能够对任意对象进行任意更改以预定方式和实时方式进行仿真的框架。

最佳答案

what is the most efficient way to implement such a bit-mask

std::vector<bool>那里和个人资料。如果/当您发现自己花费大量时间处理该 vector 时,请进一步阅读。

没有最有效的方法,这完全取决于您的代码究竟如何处理这些位。

一种标准方法是保留连续的整数 vector ,并将它们视为位 vector 。例如,std::vector<bool>在 Windows 上使用 32 位值,每个值保留 32 个 bool 值。

但是std::vector的API太笼统了。如果你的 vector 有大部分 0-s,或大部分 1-s,你将能够比 std::vector<bool> 更快地实现许多操作(获取值,找到第一个/下一个/前一个 0/​​1)。

另外,根据您的访问模式,您可能需要更小或更大的元素。如果您决定使用大型 SIMD 类型,即 __m128i__m256i不要忘记对齐它们。

关于c++ - 我需要 C++ 中的无限位掩​​码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48833070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com