Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is shared memory array returned by CreateFileMapping/MapViewOfFile zero initialized?

Just curious if I'm creating a shared memory array on Windows platform like so:

HANDLE hFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE | SEC_COMMIT, 0, 1024 * 4, _T("mySharedMemName"));
if(hFile)
{
    VOID* pData = MapViewOfFile(hFile, FILE_MAP_ALL_ACCESS, 0, 0, 1024 * 4);

    //Is 'pData' array initialized with zeros the first time the 'hFile' is used?
}

Is the memory array initialized with 0's the first time I call this code snippet? And if no, how to make it zero initialized?

like image 552
ahmd0 Avatar asked Jun 17 '12 00:06

ahmd0


Video Answer


1 Answers

From the documentation:

The initial contents of the pages in a file mapping object backed by the operating system paging file are 0 (zero).

like image 139
Luke Avatar answered Sep 20 '22 11:09

Luke