471,605 Members | 1,607 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 software developers and data experts.

fileMappig with paging

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

Jan 20 '06 #1
2 1988
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.

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"Vlad" <a.*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com... 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

Jan 20 '06 #2
The trouble is exactly this.
Thanks!

Jan 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Shawn | last post: by
2 posts views Thread by asad | last post: by
2 posts views Thread by rn5a | last post: by
5 posts views Thread by Donald Adams | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.