我已经在代码中映射了70M并将其复制,在Linux系统(centos)中它仅花费10ms,而在IOS中则花费1000〜2000ms(iphone 7P 64GB,iphone 6)。 munmap()中的Linux和IOS之间有什么不同?什么情况会导致munmap()变慢?
size_t dataLength;
void * dataPtr;
size_t dataReadLength;
void * dataReadPtr;
printf("start mmap \n");
FILE *dfile = fopen(destfile, "wb");
long dfilelen = getFileSize(sourcefile);
fseek(dfile, dfilelen - 1, 0);
// append the null to the dfile
fwrite("0", 1, 1, dfile);
fclose(dfile);
int ierr_dest = MapFileNew(destfile, &dataPtr, &dataLength, O_RDWR);
int ierr_source = MapFileNew(sourcefile, &dataReadPtr, &dataReadLength, O_RDONLY);
memcpy((char *)dataPtr, (char *)dataReadPtr, dfilelen);
StartTime = getTime();
munmap(dataReadPtr, dataLength);
iEndTime = getTime();
printf("the munmap read cost time is %d,dataLength is %d \n",iEndTime - iStartTime, dataLength);
iStartTime = getTime();
msync((void *)dataPtr, dataLength, MS_SYNC);
// this cost long time in the IOS
munmap(dataPtr, dataLength);
iEndTime = getTime();
printf("the munmap write cost time is %d,dataLength is %d \n",iEndTime - iStartTime, dataLength);