shape.input: when reading from mapped memory cache keep a mapped_region_ptr member to ensure the memory stays alive - refs #1877

This commit is contained in:
Dane Springmeyer 2013-05-30 14:32:20 -07:00
parent af8b5d8e40
commit 370609feed
3 changed files with 14 additions and 1 deletions

View file

@ -62,8 +62,13 @@ dbf_file::dbf_file(std::string const& file_name)
boost::optional<mapnik::mapped_region_ptr> memory = mapped_memory_cache::instance().find(file_name,true);
if (memory)
{
mapped_region_ = *memory;
file_.buffer(static_cast<char*>((*memory)->get_address()),(*memory)->get_size());
}
else
{
throw std::runtime_error("could not create file mapping for "+file_name);
}
#endif
if (file_)
{

View file

@ -27,6 +27,7 @@
#include <mapnik/feature.hpp>
#include <mapnik/noncopyable.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/mapped_memory_cache.hpp>
// boost
#include <boost/interprocess/streams/bufferstream.hpp>
@ -57,6 +58,7 @@ private:
std::vector<field_descriptor> fields_;
#ifdef SHAPE_MEMORY_MAPPED_FILE
boost::interprocess::ibufferstream file_;
mapnik::mapped_region_ptr mapped_region_;
#else
std::ifstream file_;
#endif

View file

@ -138,6 +138,7 @@ public:
#ifdef SHAPE_MEMORY_MAPPED_FILE
typedef ibufferstream file_source_type;
typedef shape_record<MappedRecordTag> record_type;
mapnik::mapped_region_ptr mapped_region_;
#else
typedef std::ifstream file_source_type;
typedef shape_record<RecordTag> record_type;
@ -162,7 +163,12 @@ public:
if (memory)
{
file_.buffer(static_cast<char*>((*memory)->get_address()), (*memory)->get_size());
mapped_region_ = *memory;
file_.buffer(static_cast<char*>((*memory)->get_address()),(*memory)->get_size());
}
else
{
throw std::runtime_error("could not create file mapping for "+file_name);
}
#endif
}