fileMappig with paging

  • Thread starter Thread starter Vlad
  • Start date Start date
V

Vlad

I'll do a mappig of a big file using a paging for reader it.
The first time I call CreateFileMapping and MapViewOfFile with a page
of 655360, the pointer is not null; then I want to read another page
and I used UnmapViewOfFile, CloseHandle and callback MapViewOfFile.
but the pointer is null.

The method that make a new paging:

public int MapFile(long offSet)
{
IntegerType iType=new IntegerType();

//The start address of the new page
long _addrStart;
_addrStart =(long) (Math.Ceiling((decimal)((offSet)
/ _pageSize))) * _pageSize;

if (_pTofile.ToPointer() != null)
{
//Dispose
Winapi.UnmapViewOfFile(_pTofile);
_pTofile = new IntPtr(null);

//Winapi.CloseHandle(_hMap);
//_hMap = new IntPtr(null);
}
else
_hMap =
Winapi.CreateFileMapping(_hFile.DangerousGetHandle(), IntPtr.Zero,
Winapi.myEnumProtect.PAGE_READONLY, 0,
(int)_sFile,
indexFile.ToString());

indexFile++;
_pTofile = Winapi.MapViewOfFile(_hMap,
Winapi.myenumFileMap.FILE_MAP_READ,
iType.HIWORD(_addrStart),
iType.LOWORD(_addrStart),
(int)_pageSize);


}
It's corret the dispose methods
Can someone help me? Thanks
 
Just a hint in the docs MapViewOfFile accepts low and hight portions of the
offset,
that is lower and higher 32 bits of the 64 bit value, right?

Maybe the trouble is that iType.LOWORD and iType.HIWORD are operating with
WORDs ( 16 bit ) and
not DWORD ( 32 bit )?
Winapi.MapViewOfFile(_hMap,
Winapi.myenumFileMap.FILE_MAP_READ,
iType.HIWORD(_addrStart),
iType.LOWORD(_addrStart),
(int)_pageSize);

About disposing, why aren't you checking return results from
UnmapViewOfFile?
Except this I think that disposing is okay.
 
Back
Top