如何有效地从标准:d创建D3D缓冲区
How to efficiently create D3D Buffer from std::deque
众所周知,std::deque< T >
由数据块组成(数组数组或数组列表,我不知道(。如果T
的大小足够小,则通常创建的每个块的大小为 4k。(我相信(libc++和libstdc++也是如此(如果我错了,请纠正我(。4k 是 x86/x64 平台的页面大小(我相信(。
我逐个收集数据并将其存储在std::deque
中。最后,我应该使用其API将其传递给DirectX缓冲区。
我是否可以访问std::deque
的各个块,以便一次加载它们(没有提交实现详细信息(,但不能逐个加载T
类型的值?
拥有这样的接口会很棒 std::deque
,它允许实现固有的期望。比如说,std::unordered_{set,map}
有存储桶(无法访问它们(。新开发的try设计允许将单个节点从一个容器移动到另一个容器等。
你自己用指针算术检查块怎么样?下面是一个填充std::deque
的示例,然后为每个块的开头提供迭代器:
#include <iostream>
#include <deque>
#include <vector>
#include <algorithm>
int main()
{
typedef int MyType;
std::deque<MyType> myInts(10000);
//fill the array
int count = 0;
std::generate(myInts.begin(), myInts.end(), [&](){ return ++count; });
//chunks' beginnings container
std::vector<std::deque<MyType>::iterator> myIntsChunks;
myIntsChunks.push_back(myInts.begin());
for(std::deque<MyType>::iterator it = myInts.begin()+1; it != myInts.end(); it++)
{
if(&(*(it-1)) != ((&(*(it)))-1)) //if this element's pointer isn't right after the previous element's pointer
{
myIntsChunks.push_back(it);
}
}
std::cout<<"I found " << myIntsChunks.size() << " chunk(s)." << std::endl;
std::for_each(myIntsChunks.begin(), myIntsChunks.end(),
[&myInts](const std::deque<MyType>::iterator& it)
{
std::cout<<"Chunk starts at " << std::distance(myInts.begin(),it) << std::endl;
});
}
如果您将该std::deque
更改为std::vector
,您将只会得到一个块!
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 使用std::multimap迭代器创建std::list
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 使用CMake创建QML插件
- 如何在c++中为模板函数实例创建快捷方式
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 试图在visual studio上用C++创建一个桌面应用程序
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 如何在C++20中创建模板别名的推导指南
- 如何为模板化对象创建模板向量?VS正在投掷C3203
- 如何创建一个空的全局类并在启动时实例化它
- 无法创建抽象类的实例
- 链接到自行创建的dll失败
- 在VC++中从DLLMAIN内部调用D3D的CREATEDEVICE时,它会创建一个死锁(loaderlock?)。有没有办法克服这个问题?最终目标内
- 如何有效地从标准:d创建D3D缓冲区
- 如何在C 中创建一个IDIRECT3DSURFACE9(D3D表面)表面的数组
- 创建没有HWND输入参数到MSFT createVice()函数的D3D设备
- 创建D3D设备后无法进行双重计算