views:

21

answers:

0

I am using mmap in windows for fast file I/O. Following is my code for your refrence. Windows specific code for mmaping.

m_fHandle = CreateFile(m_sFileName,GENERIC_READ|GENERIC_WRITE,

   FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

if (!m_fHandle) 

{

           //Log Message to signal failure

    error_exit("DPStrippedPartition::InitMMap" ,PARTITION_ERR,pmA2U("Error opening file for writing" ));

    return IFAILURE;

}

int buff[1];

buff[0]=1;

DWORD dwBytesWritten;

WriteFile (m_fHandle, buff, 1,

             &dwBytesWritten, NULL);



m_mapHandle = CreateFileMapping(m_fHandle, NULL, PAGE_READWRITE, 0,10240, NULL);



if (!m_mapHandle) 

{ 

           error_exit("DPStrippedPartition::InitMMap" ,PARTITION_ERR,

       pmA2U("Error creating file mapping"));

           CloseHandle(m_fHandle);

           return IFAILURE;

}

m_map = (IINT32*)MapViewOfFile(m_mapHandle, FILE_MAP_ALL_ACCESS,0,0,10240);

if (!m_map) 

{

   error_exit("DPStrippedPartition::InitMMap" ,PARTITION_ERR,

       pmA2U("Error creating map view of the file"));

   CloseHandle(m_mapHandle); 

   CloseHandle(m_fHandle); 

           return IFAILURE;

}

m_bIsMapInitzd = ITRUE;

return ISUCCESS;

I gave the size as 10240 but still at index 3072 of m_map, the crash happens saying access violation.

Can anybody help me track the issue?

Sincerely, Akhtar