Commit 220ca3b7 authored by Martin Schultz's avatar Martin Schultz

Merge branch 'fastObjLoader' of...

Merge branch 'fastObjLoader' of ssh://Renault.informatik.rwth-aachen.de/data/git-repository/acgl/libraries/acgl into fastObjLoader
parents e4c4a3db 8c672f65
...@@ -54,8 +54,8 @@ namespace ACGL{ ...@@ -54,8 +54,8 @@ namespace ACGL{
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
enum shareMode enum shareMode
{ {
MAP_PRIVATE, MAPPING_PRIVATE,
MAP_SHARED MAPPING_SHARED
}; };
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
...@@ -99,7 +99,7 @@ namespace ACGL{ ...@@ -99,7 +99,7 @@ namespace ACGL{
********************************************************************/ ********************************************************************/
MemoryMappedFile( const char* _fileName, MemoryMappedFile( const char* _fileName,
accessMode _accessMode = accessMode::READ_ONLY, accessMode _accessMode = accessMode::READ_ONLY,
shareMode _shareMode = shareMode::MAP_PRIVATE, shareMode _shareMode = shareMode::MAPPING_PRIVATE,
size_t _length = 0, size_t _length = 0,
off_t _offset = 0); off_t _offset = 0);
...@@ -125,4 +125,4 @@ namespace ACGL{ ...@@ -125,4 +125,4 @@ namespace ACGL{
}; };
} }
} }
\ No newline at end of file
...@@ -24,5 +24,12 @@ ...@@ -24,5 +24,12 @@
off_t length(); off_t length();
off_t length() const; off_t length() const;
~MemoryMappedFilePosixImpl(); ~MemoryMappedFilePosixImpl();
private:
int mFileHandle;
off_t mPageOffset;
off_t mLength;
char* mpData;
int mErrorCode;
}; };
#endif #endif
\ No newline at end of file
...@@ -6,49 +6,106 @@ ...@@ -6,49 +6,106 @@
#pragma once #pragma once
#ifdef __unix #ifdef __unix
#include "ACGL/Utils/MemoryMappedFilePosixImpl.hh" #include "ACGL/Utils/MemoryMappedFilePosixImpl.hh"
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
MemoryMappedFilePosixImpl::MemoryMappedFilePosixImpl( MemoryMappedFilePosixImpl::MemoryMappedFilePosixImpl(
const char* _fileName, const char* _fileName,
ACGL::Utils::MemoryMappedFile::accessMode _accessMode, ACGL::Utils::MemoryMappedFile::accessMode _accessMode,
ACGL::Utils::MemoryMappedFile::shareMode _shareMode, ACGL::Utils::MemoryMappedFile::shareMode _shareMode,
size_t _length, size_t _length,
off_t _offset) off_t _offset):
mFileHandle(NULL),
mPageOffset(0),
mpData(nullptr),
mErrorCode(0)
{ {
int pageAccess = 0;
int pageShare = 0;
if(_shareMode == ACGL::Utils::MemoryMappedFile::MAPPING_SHARED)
pageShare = MAP_SHARED;
else
pageShare = MAP_PRIVATE;
if(_accessMode == ACGL::Utils::MemoryMappedFile::READ_ONLY)
{
mFileHandle = open(_fileName,O_RDONLY);
pageAccess = PROT_READ;
}
else
{
mFileHandle = open(_fileName, O_RDWR);
pageAccess = PROT_READ | PROT_WRITE;
}
if(mFileHandle == NULL)
{
mErrorCode = 2;
ACGL::Utils::error()<<"Could not map the File: "<<_fileName<<" to Ram. File was not found"<<std::endl;
return;
}
if(_length <= 0)
{
struct stat fileStat;
stat(_fileName, &fileStat);
mLength = fileStat.st_size;
}
if(_offset > 0)
{
mPageOffset = _offset % sysconf(_SC_PAGE_SIZE);
mLength -= _offset;
}
mpData = reinterpret_cast<char*>(mmap(nullptr, mLength, pageAccess, pageShare,
mFileHandle, _offset - mPageOffset));
if(!mpData)
{
ACGL::Utils::error()<<"could not map the File: "<<_fileName<<" to Ram. Error when calling mmap (are you shure offset and length are correct?)"<<std::endl;
}
} }
char * MemoryMappedFilePosixImpl::data() char * MemoryMappedFilePosixImpl::data()
{ {
return 0; return mpData;
} }
const char * MemoryMappedFilePosixImpl::data() const const char * MemoryMappedFilePosixImpl::data() const
{ {
return 0; return mpData;
} }
int MemoryMappedFilePosixImpl::errorCode() int MemoryMappedFilePosixImpl::errorCode()
{ {
return 0; return mErrorCode;
} }
int MemoryMappedFilePosixImpl::errorCode() const int MemoryMappedFilePosixImpl::errorCode() const
{ {
return 0; return mErrorCode;
} }
off_t MemoryMappedFilePosixImpl::pageOffset() off_t MemoryMappedFilePosixImpl::pageOffset()
{ {
return 0; return mPageOffset;
} }
off_t MemoryMappedFilePosixImpl::pageOffset() const off_t MemoryMappedFilePosixImpl::pageOffset() const
{ {
return 0; return mPageOffset;
} }
off_t MemoryMappedFilePosixImpl::length() off_t MemoryMappedFilePosixImpl::length()
{ {
return 0; return mLength;
} }
off_t MemoryMappedFilePosixImpl::length() const off_t MemoryMappedFilePosixImpl::length() const
{ {
return 0; return mLength;
} }
MemoryMappedFilePosixImpl::~MemoryMappedFilePosixImpl() MemoryMappedFilePosixImpl::~MemoryMappedFilePosixImpl()
{ {
if(mpData)
munmap(mpData,mLength);
if(mFileHandle)
close(mFileHandle);
} }
#endif #endif
...@@ -35,7 +35,7 @@ MemoryMappedFileWinImpl::MemoryMappedFileWinImpl( ...@@ -35,7 +35,7 @@ MemoryMappedFileWinImpl::MemoryMappedFileWinImpl(
// //
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
if (_shareMode == ACGL::Utils::MemoryMappedFile::MAP_SHARED) if (_shareMode == ACGL::Utils::MemoryMappedFile::MAPPING_SHARED)
{ {
fileShare = FILE_SHARE_READ | FILE_SHARE_WRITE; fileShare = FILE_SHARE_READ | FILE_SHARE_WRITE;
...@@ -82,7 +82,7 @@ MemoryMappedFileWinImpl::MemoryMappedFileWinImpl( ...@@ -82,7 +82,7 @@ MemoryMappedFileWinImpl::MemoryMappedFileWinImpl(
SYSTEM_INFO info; SYSTEM_INFO info;
GetSystemInfo(&info); GetSystemInfo(&info);
mPageOffset = _offset % info.dwAllocationGranularity; mPageOffset = _offset % info.dwAllocationGranularity;
mapSize -= (_offset - mPageOffset); mapSize -= (_offset);
} }
if (_length > 0 ) if (_length > 0 )
{ {
...@@ -98,7 +98,7 @@ MemoryMappedFileWinImpl::MemoryMappedFileWinImpl( ...@@ -98,7 +98,7 @@ MemoryMappedFileWinImpl::MemoryMappedFileWinImpl(
} }
//create the file mapping view //create the file mapping view
mpData = reinterpret_cast<PCHAR> mpData = reinterpret_cast<PCHAR>
(MapViewOfFile(mFileMappingHandle, mapViewAccess, offsetHigh, offsetLow - mPageOffset, mapSize)); (MapViewOfFile(mFileMappingHandle, mapViewAccess, offsetHigh, offsetLow, mapSize));
if (!mpData) if (!mpData)
{ {
mErrorCode = GetLastError(); mErrorCode = GetLastError();
...@@ -148,4 +148,4 @@ MemoryMappedFileWinImpl::~MemoryMappedFileWinImpl() ...@@ -148,4 +148,4 @@ MemoryMappedFileWinImpl::~MemoryMappedFileWinImpl()
CloseHandle(mFileHandle); CloseHandle(mFileHandle);
} }
#endif #endif
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment