How to insert 100G integers into a vector on a 32-bit machine?

Say I have 100 GB integers and you want to paste them into vector<int>a 32-bit machine, is this possible?

If I use custom to manage the storage strategy allocator, how can I ensure that the following operations are always valid:

vector<int> coll;
coll.insert(100G integers);
memcpy(coll.begin() + (1024 * 1024 * 1024 * 8), "Hello", 5);

Please note that for the C ++ standard, objects stored in vectormust be sequential. coll.begin() + (1024 * 1024 * 1024 * 8)may be the address of the hard drive.

+4
source share
3 answers

100 G , 400 ; 32- 2, 3 4 , - 64 PAE. , 32- 32- , 4 .

STL size_t (libstd++ GCC, libcxx LLVM + , STLPort , Microsoft Microsoft...) STL, (32-), .

STL, . STXXL, http://stxxl.sourceforge.net/ ( ), STL (HDD) . ( , , 400 ) SSD , .

STXXL : . . STXXL - . ( ).

STXXL 32- ; , - 32- ... STL, size_t, ...

+9

, . , . sizeof(int) 1, 100 , 32- 4 .

- , , . std::vector , ( , ).

+7

You can try using Boost.Interprocess managed_mapped_file . sample:

#include <iostream>
#include <vector>
#include <boost/interprocess/managed_mapped_file.hpp>
#include <boost/interprocess/allocators/allocator.hpp>

int main()
{
    namespace ipc = boost::interprocess;

    using allocator_t = ipc::allocator<int, ipc::managed_mapped_file::segment_manager>;
    using vector_t = std::vector<int, allocator_t>;

    const char* filename = "tmp.dat";
    ipc::managed_mapped_file::size_type filesize = 4096;

    ipc::file_mapping::remove(filename);
    ipc::managed_mapped_file mfile(ipc::create_only, filename, filesize);

    vector_t* vec = mfile.construct<vector_t>("MyVector")(mfile.get_segment_manager());

    vec->resize(10, 42);
    for (int x : *vec) {
        std::cout << x << std::endl;
    }
}
+3
source

All Articles