mmap tarfiles directly when mmapping is enabled, instead of copying data into separate mmapped block
Co-authored-by: Kajari Ghosh <ghoshkaj@gmail.com>
This commit is contained in:
+17
-16
@@ -15,14 +15,14 @@ namespace util
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename T, typename RegionT>
|
||||
util::vector_view<T> mmapFile(const boost::filesystem::path &file, RegionT ®ion)
|
||||
template <typename T, typename MmapContainerT>
|
||||
util::vector_view<T> mmapFile(const boost::filesystem::path &file, MmapContainerT &mmap_container)
|
||||
{
|
||||
try
|
||||
{
|
||||
region.open(file);
|
||||
std::size_t num_objects = region.size() / sizeof(T);
|
||||
auto data_ptr = region.data();
|
||||
mmap_container.open(file);
|
||||
std::size_t num_objects = mmap_container.size() / sizeof(T);
|
||||
auto data_ptr = mmap_container.data();
|
||||
BOOST_ASSERT(reinterpret_cast<uintptr_t>(data_ptr) % alignof(T) == 0);
|
||||
return util::vector_view<T>(reinterpret_cast<T *>(data_ptr), num_objects);
|
||||
}
|
||||
@@ -34,9 +34,10 @@ util::vector_view<T> mmapFile(const boost::filesystem::path &file, RegionT ®i
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename RegionT>
|
||||
util::vector_view<T>
|
||||
mmapFile(const boost::filesystem::path &file, RegionT ®ion, const std::size_t size)
|
||||
template <typename T, typename MmapContainerT>
|
||||
util::vector_view<T> mmapFile(const boost::filesystem::path &file,
|
||||
MmapContainerT &mmap_container,
|
||||
const std::size_t size)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -45,10 +46,10 @@ mmapFile(const boost::filesystem::path &file, RegionT ®ion, const std::size_t
|
||||
params.path = file.string();
|
||||
params.flags = boost::iostreams::mapped_file::readwrite;
|
||||
params.new_file_size = size;
|
||||
region.open(params);
|
||||
mmap_container.open(params);
|
||||
|
||||
std::size_t num_objects = size / sizeof(T);
|
||||
auto data_ptr = region.data();
|
||||
auto data_ptr = mmap_container.data();
|
||||
BOOST_ASSERT(reinterpret_cast<uintptr_t>(data_ptr) % alignof(T) == 0);
|
||||
return util::vector_view<T>(reinterpret_cast<T *>(data_ptr), num_objects);
|
||||
}
|
||||
@@ -63,24 +64,24 @@ mmapFile(const boost::filesystem::path &file, RegionT ®ion, const std::size_t
|
||||
|
||||
template <typename T>
|
||||
util::vector_view<const T> mmapFile(const boost::filesystem::path &file,
|
||||
boost::iostreams::mapped_file_source ®ion)
|
||||
boost::iostreams::mapped_file_source &mmap_container)
|
||||
{
|
||||
return detail::mmapFile<const T>(file, region);
|
||||
return detail::mmapFile<const T>(file, mmap_container);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
util::vector_view<T> mmapFile(const boost::filesystem::path &file,
|
||||
boost::iostreams::mapped_file ®ion)
|
||||
boost::iostreams::mapped_file &mmap_container)
|
||||
{
|
||||
return detail::mmapFile<T>(file, region);
|
||||
return detail::mmapFile<T>(file, mmap_container);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
util::vector_view<T> mmapFile(const boost::filesystem::path &file,
|
||||
boost::iostreams::mapped_file ®ion,
|
||||
boost::iostreams::mapped_file &mmap_container,
|
||||
std::size_t size)
|
||||
{
|
||||
return detail::mmapFile<T>(file, region, size);
|
||||
return detail::mmapFile<T>(file, mmap_container, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user