如何有效地从标准:d创建D3D缓冲区

How to efficiently create D3D Buffer from std::deque

本文关键字:创建 D3D 缓冲区 标准 有效地      更新时间:2023-10-16

众所周知,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,您将只会得到一个块!