Is the shared memory array returned using CreateFileMapping / MapViewOfFile zero initialized?

Just wondering if I am creating an array of shared memory on a Windows platform, for example:

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 a memory array initialized to 0 with the first call to this piece of code? And if not, how to make it zero initialized?

+6
source share
1 answer

From the documentation :

The original content of the pages in the file mapping object supported by the operating system swap file is 0 (zero).

+7
source

Source: https://habr.com/ru/post/918263/


All Articles