Exemplo n.º 1
0
main(void)
{
	AllocateMemory(100, 4);
	MapView();
	printf("\n\n");
	DetailedInfo();
	DeallocateMemory();
}
Exemplo n.º 2
0
 MappedFile& MappedFile::operator=(const MappedFile & other){
     file = dup( other.file );
     if( file == -1 ){
         throw Exception::ErrNo("Couldn't dup file descriptor");
     }
     file_size = other.file_size;
     full_name = other.full_name;
     MapView(other.desiredaccess);
     return *this;
 }
Exemplo n.º 3
0
Arquivo: BZDoc.cpp Projeto: tnzk/bz
void CBZDoc::Serialize(CArchive& ar)
{
    MEMORYSTATUS ms;
    GlobalMemoryStatus(&ms);

    CFile *pFile = ar.GetFile();
    ar.Flush();

    if (ar.IsLoading())	{
        // TODO: add loading code here
        m_dwTotal = GetFileLength(pFile);
#ifdef FILE_MAPPING
        if(IsFileMapping()) {
            if(!MapView()) return;
        } else
#endif //FILE_MAPPING
        {
            if(!(m_pData = (LPBYTE)MemAlloc(m_dwTotal))) {
                AfxMessageBox(IDS_ERR_MALLOC);
                return;
            }
            DWORD len = pFile->Read(m_pData, m_dwTotal);
            if(len < m_dwTotal) {
                AfxMessageBox(IDS_ERR_READFILE);
                MemFree(m_pData);	// ###1.61
                m_pData = NULL;
                return;
            }
            m_bReadOnly = options.bReadOnlyOpen;
        }
    } else {
        // TODO: add storing code here
#ifdef FILE_MAPPING
        if(IsFileMapping()) {
            BOOL bResult = (m_pMapStart) ? ::FlushViewOfFile(m_pMapStart, m_dwMapSize) : ::FlushViewOfFile(m_pData, m_dwTotal);
            if(!bResult) {
                ErrorMessageBox();
            }
        } else
#endif //FILE_MAPPING
            pFile->Write(m_pData, m_dwTotal);
        m_dwUndoSaved = m_dwUndo;		// ###1.54
        TouchDoc();
        /*		if(m_pUndo) {
        			MemFree(m_pUndo);
        			m_pUndo = NULL;
        		}
        */
    }
}
Exemplo n.º 4
0
    MappedFile::MappedFile( const std::string & fileName, const std::vector<std::string> & include_paths, MappedFile::Access access ){
        int faccess = 0;
        desiredaccess = 0;
        if (access == Access::Read){
            faccess = O_RDONLY;
            desiredaccess = PROT_READ;
        }
        else if (access == Access::ReadWrite){
            faccess = O_RDWR;
            desiredaccess = PROT_READ | PROT_WRITE;
        }
        std::string testFileName;
        file = -1;
        for (const auto & path : include_paths){
            testFileName = path;
            if (testFileName.back() != '\\' && testFileName.back() != '/'){
                testFileName += '/';
            }
            testFileName += fileName;
            file = open( testFileName.c_str(), faccess, 0 );
            if ( file != -1 ){
                break;
            }
        }
        if (file == -1){
            testFileName = fileName;
            file = open(testFileName.c_str(), faccess, 0 );
        }
        if (file == -1){
            throw Exception::ErrNo("Could not open " + fileName);
        }

        struct stat st;
        fstat(file, &st);
        file_size = st.st_size;

        char buffer[PATH_MAX];
        if( realpath(testFileName.c_str(), buffer) == nullptr ){
            throw Exception::ErrNo();
        }

        full_name = buffer;

        MapView(desiredaccess);

    }
Exemplo n.º 5
0
VOID Mesh::DataTable::Iterate(Func F, UINT Offset, U& P0, V& P1)
{
  MapView(PageAccess::READWRITE);

  UINT Stride = m_pHeader->ElementSize;
  LPBYTE pData = (LPBYTE)m_pData + Offset;

  UINT j = 0;
  for (UINT i=0; i<m_pHeader->Count; i++, pData+=Stride)
  {
    F(i, *(T*)pData, P0, P1);

    if (i - j > 1048576)
    {
      Unlock(j, i - j - 65536);
      j = i-65536;
    }
  }

  Unmap();
}