开发者

Why is Linux msync is returning "Cannot Allocate memory"? Is it possible to fix this error code?

Good afternoon, We are building a prototype deduper for Centos Linux Release x86_32 and Microsoft Windows. One part of the prototype is a MemoryMappedFile program which uses a 1800 element cache. For Centos Linux 5.5 we call msync to synchronize the file with the memory map. For the last several weeks, msync has been functioning okay. Today, msync and perror("msync") are returning "Cannot allocate memory". Why is Centos Linux Version 5.5 x86_32 msync returning "Cannot Allocate memory"? Is it possible for use to fix the "Cannot Allocate memory" error on Centos Linux 5.5 x86_32. Thank you. An excerpt of the memory mapped file program code is shown below:

        typedef std::multimap<char *,Range>::const_iterator I;  
    std::pair<I,I> b = mmultimap.equal_range(TmpPrevMapPtr); 
         for (I i=b.first; i != b开发者_开发百科.second; ++i){ 
    std::deque<Range>::iterator iter;
    iter = std::lower_bound(ranges_type.begin(),ranges_type.end(),i->second);
              if (iter != ranges_type.end() && !(i->second < *iter)){
        sz1 = ranges_type.size();
                        ranges_type.erase(iter);
        sz2 = ranges_type.size();
    }
    }
    erasecount = mmultimap.erase(TmpPrevMapPtr); 
    #if defined(__windows)
    retval = FlushViewOfFile(TmpPrevMapPtr, mappedlength);
    retval =    UnmapViewOfFile(TmpPrevMapPtr);            
    #elif defined(__unix)
         retval = msync(TmpPrevMapPtr,   mappedlength, MS_SYNC);    
    if (retval == -1){                                        
       perror("msync");                                       
         }                                                       
         retval = munmap(TmpPrevMapPtr,  mappedlength);
    if (retval == -1){                    
       perror("munmap");                        
           throw cException(ERR_MEMORYMAPPING,TempFileName);
         }
    #endif


The msync man page states:

 ENOMEM The indicated memory (or part of it) was not mapped.

That's the errno value perror() prints for you. So you're somehow trying to msync() memory that you've not mmap()'ed from a file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜