gpt4 book ai didi

c++ - 如何创建具有 64 位索引的 std::vector?

转载 作者:太空狗 更新时间:2023-10-29 23:34:40 24 4
gpt4 key购买 nike

我想创建一个big std::vector 所以operator[] 应该接收long long 而不是比 unsigned int,我尝试编写自己的分配器:

template <typename T>
struct allocator64 : std::allocator<T> {
typedef long long difference_type;
typedef unsigned long long size_type;
};

但是当我尝试以下操作时:

long long n = 5;
std::vector<int, allocator64<int> > vec(n);
vec[n-1] = 2;

我在第二行和第三行收到以下警告:

warning C4244: 'argument' : conversion from '__int64' to 'unsigned int', possible loss of data

我错过了什么?我认为 operator[] 和 size 构造函数的类型应该来自 allocator::size_type

我正在使用 VS9 (2008)。

最佳答案

也许是 STXXL图书馆可以提供帮助:

STXXL provides an STL replacement using an abstraction layer to storage devices to allow for the optimal layout of data structures. This allows for multi-terabyte datasets to be held and manipulated in standard C++ data structures, whilst abstracting the complexity of managing this behaviour efficiently. STXXL utilises multi-disk I/O to speed up I/O bound calculations. STXXL has been developed at the University of Karlsruhe.

关于c++ - 如何创建具有 64 位索引的 std::vector?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1936013/

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