Hi, I want improve the rendering of vector features in QGIS.
I have opened a new branch of code in the repository of
QGIS(https://github.com/qgis/QGIS/pull/927 //
https://github.com/ahuarte47/QGIS/tree/Issue_8725-OGR) and the drawing tests
give me ~3x faster that original code :-)
I am testing with huge shapefiles (>500.000 records) and I have detect that the
OGR-shapefile provider would be optimized using filemapping (boost
<http://www.boost.org/>, or others...)
I wonder if there is any support for FileMapping in gdal or planned. My
intention would be to redefine the access to the files in this provider with a
new function with "SAHooks" using FileMapping. I provide, as explanation, an
unfinished implementation using boost with which greatly speeds up the read of
files for critical, massive and repetitive processes such as the painting in a
map.
On the other hand, this provider may also accelerate with some small changes
that are pending of review in the ticket
(http://trac.osgeo.org/gdal/ticket/5272) that I hope will be evaluated.
thank you very much!
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// TEST BOOST - MEMORY MAPPING FILE
#include <boost/filesystem.hpp>
#include <boost/iostreams/device/mapped_file.hpp>
#define ROOT_LIB_PATH( __RELATIVE_PATH ) "/TFS_OSGeo/SIT/SIG_SDK/Open
Source/boost-1.54.0"#__RELATIVE_PATH
#if _DEBUG
#pragma comment(lib, ROOT_LIB_PATH(
"/lib32-msvc-10.0/libboost_iostreams-vc100-mt-sgd-1_54.lib" ))
#pragma comment(lib, ROOT_LIB_PATH(
"/lib32-msvc-10.0/libboost_filesystem-vc100-mt-sgd-1_54.lib" ))
#else
#pragma comment(lib, ROOT_LIB_PATH(
"/lib32-msvc-10.0/libboost_iostreams-vc100-mt-s-1_54.lib" ))
#pragma comment(lib, ROOT_LIB_PATH(
"/lib32-msvc-10.0/libboost_filesystem-vc100-mt-s-1_54.lib" ))
#endif
//-------------------------------------------------------------------------------------------------------
// Helper wrapper class for boost::mapped_file.
class mapped_file_manager
{
public:
mapped_file_manager() : file(NULL), length(0), tell(0)
{
}
~mapped_file_manager()
{
close();
}
public:
boost::iostreams::mapped_file* file;
uintmax_t length;
uintmax_t tell;
public:
bool open(const char *pszFilename, bool readOnly)
{
if (boost::filesystem::exists(pszFilename))
{
boost::iostreams::mapped_file* fileP = new
boost::iostreams::mapped_file();
fileP->open(pszFilename, readOnly ?
boost::iostreams::mapped_file_source::readwrite :
boost::iostreams::mapped_file_source::readwrite);
if (fileP->is_open())
{
length =
boost::filesystem::file_size(pszFilename);
file = fileP;
return true;
}
}
return false;
}
bool close()
{
if (file)
{
length = 0;
tell = 0;
file->close();
delete file;
file = NULL;
return true;
}
return false;
}
};
SAFile MMF_SHP_Open( const char *pszFilename, const char *pszAccess )
{
if (boost::filesystem::exists(pszFilename))
{
mapped_file_manager* manager = new mapped_file_manager();
if (manager->open(pszFilename, strstr(pszAccess, "r")!=NULL))
{
#if _DEBUG
size_t size = manager->file->size();
#endif
return (SAFile)manager;
}
delete manager;
}
return NULL;
}
SAOffset MMF_SHP_Read( void *p, SAOffset size, SAOffset nmemb, SAFile file )
{
mapped_file_manager* manager = (mapped_file_manager*)file;
char* data = manager->file->data();
int memoyrSize = size*nmemb;
memcpy(p, data+manager->tell, memoyrSize);
manager->tell += memoyrSize;
return nmemb;
}
SAOffset MMF_SHP_Write( void *p, SAOffset size, SAOffset nmemb, SAFile file )
{
mapped_file_manager* manager = (mapped_file_manager*)file;
char* data = manager->file->data();
int memoyrSize = size*nmemb;
memcpy(data+manager->tell, p, memoyrSize);
manager->tell += memoyrSize;
return nmemb;
}
SAOffset MMF_SHP_Seek( SAFile file, SAOffset offset, int whence )
{
mapped_file_manager* manager = (mapped_file_manager*)file;
if (whence==SEEK_SET)
{
manager->tell = offset;
return 0;
}
else
if (whence==SEEK_END)
{
manager->tell = manager->length+offset;
return offset<0 ? 0 : 1;
}
else
if (whence==SEEK_CUR)
{
manager->tell = manager->tell+offset;
return 0;
}
return 2;
}
SAOffset MMF_SHP_Tell( SAFile file )
{
mapped_file_manager* manager = (mapped_file_manager*)file;
return (SAOffset)manager->tell;
}
int MMF_SHP_Flush( SAFile file )
{
mapped_file_manager* manager = (mapped_file_manager*)file;
// TODO:
return 0;
}
int MMF_SHP_Close( SAFile file )
{
if (file)
{
mapped_file_manager* manager = (mapped_file_manager*)file;
manager->close();
delete manager;
return 1;
}
return 0;
}
void MMF_SHP_Error( const char *message )
{
CPLError( CE_Failure, CPLE_AppDefined, "%s", message );
}
int MMF_SHP_Remove( const char *pszFilename )
{
return VSIUnlink( pszFilename );
}
//-------------------------------------------------------------------------------------------------------
void SASetupBoostlibHooks( SAHooks *psHooks )
{
psHooks->FOpen = MMF_SHP_Open;
psHooks->FRead = MMF_SHP_Read;
psHooks->FWrite = MMF_SHP_Write;
psHooks->FSeek = MMF_SHP_Seek;
psHooks->FTell = MMF_SHP_Tell;
psHooks->FFlush = MMF_SHP_Flush;
psHooks->FClose = MMF_SHP_Close;
psHooks->Remove = MMF_SHP_Remove;
psHooks->Atof = DBFFastAtof;
psHooks->Error = MMF_SHP_Error;
}
//-------------------------------------------------------------------------------------------------------
_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev