41
132
if (FlushViewOfFile(pmaddr, 4096) == FALSE) {
133
fprintf(stderr, "FlushViewOfFile,
134
gle: 0x%08x", GetLastError());
135
exit(1);
136
}
137
138
/* Flush the complete file to backing storage */
139
if (FlushFileBuffers(fh) == FALSE) {
140
fprintf(stderr, "FlushFileBuffers,
141
gle: 0x%08x", GetLastError());
142
exit(1);
143
}
144
145
/* Explicitly unmap before closing the file */
146
if (UnmapViewOfFile(pmaddr) == FALSE) {
147
fprintf(stderr, "UnmapViewOfFile,
148
gle: 0x%08x", GetLastError());
149
exit(1);
150
}
151
152
CloseHandle(fmh);
153
CloseHandle(fh);
154
155
printf("Done.\n");
156
exit(0);
157 }
• Lines 45-75: As in the previous Linux example, we take the file name
passed through argv and open the file.
• Line 81: We retrieve the file size to use later when memory mapping.
• Line 89: We take the first step to memory mapping a file by creating
the file mapping. This step does not yet map the file into our
application’s memory space.
• Line 106: This step maps the file into our memory space.
Chapter 3 Operating SyStem SuppOrt fOr perSiStent memOry
132
if (FlushViewOfFile(pmaddr, 4096) == FALSE) {
133
fprintf(stderr, "FlushViewOfFile,
134
gle: 0x%08x", GetLastError());
135
exit(1);
136
}
137
138
/* Flush the complete file to backing storage */
139
if (FlushFileBuffers(fh) == FALSE) {
140
fprintf(stderr, "FlushFileBuffers,
141
gle: 0x%08x", GetLastError());
142
exit(1);
143
}
144
145
/* Explicitly unmap before closing the file */
146
if (UnmapViewOfFile(pmaddr) == FALSE) {
147
fprintf(stderr, "UnmapViewOfFile,
148
gle: 0x%08x", GetLastError());
149
exit(1);
150
}
151
152
CloseHandle(fmh);
153
CloseHandle(fh);
154
155
printf("Done.\n");
156
exit(0);
157 }
• Lines 45-75: As in the previous Linux example, we take the file name
passed through argv and open the file.
• Line 81: We retrieve the file size to use later when memory mapping.
• Line 89: We take the first step to memory mapping a file by creating
the file mapping. This step does not yet map the file into our
application’s memory space.
• Line 106: This step maps the file into our memory space.
Chapter 3 Operating SyStem SuppOrt fOr perSiStent memOry
