Re: Createfile and unmapview

Hi,

I have one shared memory area of 4k size, I need to
expand this size in multiples of 4k as my memory
requirements are increasing, But I want to preserve
the memory contents of the previously allocated
block.

For this i created the new map with the same name
and
larger size, and mapped the address space. But the
call to mapviewoffile is failing saying access
denied.

the code is as follows

HANDLE hMap = CreateFileMapping(INVALID_HANDLE_VALUE,
NULL,
PAGE_READWRITE | SEC_COMMIT,
0,
4 * 1024,
“tESTsHARE”);
if (hMap == NULL)
return 1;

LPVOID lpMapAddress = MapViewOfFile(hMap,
FILE_MAP_ALL_ACCESS,
0,
0,
4 * 1024);

if (lpMapAddress == NULL)
{
DWORD dwLastError = GetLastError();
return 1;
}

*(int*)lpMapAddress = 0xffffffff;

HANDLE hMap1 = CreateFileMapping(INVALID_HANDLE_VALUE,

NULL,
PAGE_READWRITE | SEC_COMMIT,
0,
4 * 1024 *2,
“tESTsHARE”);
if (hMap == NULL)
{
DWORD dwLastError = GetLastError();
return 1;
}

LPVOID lpMapAddress1 = MapViewOfFile(hMap1,
FILE_MAP_ALL_ACCESS,
0,
0,
4 * 1024 * 2);
if (lpMapAddress == NULL)
{
DWORD dwLastError = GetLastError();
return 1;
}

UnmapViewOfFile(lpMapAddress);
CloseHandle(hMap);

Is it possible the way i am trying to reallocate the
memory area or will i have to copy the contents
manually…

Regards,
manish


Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

You can’t create 2 mappings with the same name, thats for sure.
To resolve this you may:

  1. call MapView with a different size
  2. Copy the content of the block to the new map.
    Regards,
    Stas

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Manish Sapariya
Sent: Friday, March 02, 2001 8:56 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Createfile and unmapview

Hi,

I have one shared memory area of 4k size, I need to
expand this size in multiples of 4k as my memory
requirements are increasing, But I want to preserve
the memory contents of the previously allocated
block.

For this i created the new map with the same name
and
larger size, and mapped the address space. But the
call to mapviewoffile is failing saying access
denied.

the code is as follows

HANDLE hMap = CreateFileMapping(INVALID_HANDLE_VALUE,
NULL,
PAGE_READWRITE | SEC_COMMIT,
0,
4 * 1024,
“tESTsHARE”);
if (hMap == NULL)
return 1;

LPVOID lpMapAddress = MapViewOfFile(hMap,
FILE_MAP_ALL_ACCESS,
0,
0,
4 * 1024);

if (lpMapAddress == NULL)
{
DWORD dwLastError = GetLastError();
return 1;
}

*(int*)lpMapAddress = 0xffffffff;

HANDLE hMap1 = CreateFileMapping(INVALID_HANDLE_VALUE,

NULL,
PAGE_READWRITE | SEC_COMMIT,
0,
4 * 1024 *2,
“tESTsHARE”);
if (hMap == NULL)
{
DWORD dwLastError = GetLastError();
return 1;
}

LPVOID lpMapAddress1 = MapViewOfFile(hMap1,
FILE_MAP_ALL_ACCESS,
0,
0,
4 * 1024 * 2);
if (lpMapAddress == NULL)
{
DWORD dwLastError = GetLastError();
return 1;
}

UnmapViewOfFile(lpMapAddress);
CloseHandle(hMap);

Is it possible the way i am trying to reallocate the
memory area or will i have to copy the contents
manually…

Regards,
manish


Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/


You are currently subscribed to ntdev as: xxxxx@powernetsys.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com