Click here to Skip to main content
16,007,809 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: a question on heap..... Pin
Bob Stanneveld8-May-05 1:14
Bob Stanneveld8-May-05 1:14 
GeneralRe: a question on heap..... Pin
Toby Opferman10-Jun-05 5:42
Toby Opferman10-Jun-05 5:42 
GeneralRe: a question on heap..... Pin
Bob Stanneveld10-Jun-05 9:50
Bob Stanneveld10-Jun-05 9:50 
GeneralRe: a question on heap..... Pin
Toby Opferman10-Jun-05 12:35
Toby Opferman10-Jun-05 12:35 
GeneralRe: a question on heap..... Pin
Toby Opferman10-Jun-05 12:41
Toby Opferman10-Jun-05 12:41 
GeneralRe: a question on heap..... Pin
Bob Stanneveld10-Jun-05 13:24
Bob Stanneveld10-Jun-05 13:24 
GeneralRe: a question on heap..... Pin
Toby Opferman10-Jun-05 13:36
Toby Opferman10-Jun-05 13:36 
GeneralRe: a question on heap..... Pin
Toby Opferman10-Jun-05 14:02
Toby Opferman10-Jun-05 14:02 
Take this very simple (and ugly) example, as long as you have the disk space. It will allocate a memory mapped file of 65 Gigabytes. To make this easier to use since pages can only be mapped on boundaries you could have a thin wrapper library around this to help out with that issue, but one large file can be mapped multiple views and take care of caching and writing out dirty regions.

/*************************************************************************
 *
 * Memory Mapped File Example
 *  
 *************************************************************************/


#include <windows.h>
#include <stdio.h>



int _cdecl main(void)
{
    HANDLE hFileMapping, hFile;
    PVOID pLowMemoryMap, pHighMemoryMap;

    hFile = CreateFile(L"C:\\temp.sys", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
    hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0xf, 0xffff, NULL);
        
    pHighMemoryMap = MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0xF000000, 1024*1024);
    pLowMemoryMap = MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0, 1024*1024);

    *((DWORD *)pLowMemoryMap) = 0x1234;
    *((DWORD *)pHighMemoryMap) = 0x5678;

    UnmapViewOfFile(pLowMemoryMap);
    UnmapViewOfFile(pHighMemoryMap);

    pHighMemoryMap = MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0xF000000, 1024*1024);
    pLowMemoryMap = MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0, 1024*1024);

    printf("0x%0x, 0x%0x\n", *((DWORD *)pLowMemoryMap), *((DWORD *)pHighMemoryMap));

    UnmapViewOfFile(pLowMemoryMap);
    UnmapViewOfFile(pHighMemoryMap);

    CloseHandle(hFileMapping);

    CloseHandle(hFile);

    return 0;
} 






8bc7c0ec02c0e404c0cc0680f7018827ebee
GeneralRe: a question on heap..... Pin
Bob Stanneveld11-Jun-05 1:25
Bob Stanneveld11-Jun-05 1:25 
GeneralRe: a question on heap..... Pin
Toby Opferman11-Jun-05 7:49
Toby Opferman11-Jun-05 7:49 
GeneralRe: a question on heap..... Pin
Bob Stanneveld12-Jun-05 6:00
Bob Stanneveld12-Jun-05 6:00 
GeneralRe: a question on heap..... Pin
Toby Opferman12-Jun-05 7:32
Toby Opferman12-Jun-05 7:32 
GeneralRe: a question on heap..... Pin
Toby Opferman12-Jun-05 7:52
Toby Opferman12-Jun-05 7:52 
GeneralRe: a question on heap..... Pin
Toby Opferman12-Jun-05 8:21
Toby Opferman12-Jun-05 8:21 
GeneralRe: a question on heap..... Pin
Bob Stanneveld12-Jun-05 20:47
Bob Stanneveld12-Jun-05 20:47 
GeneralRe: a question on heap..... Pin
Toby Opferman13-Jun-05 10:28
Toby Opferman13-Jun-05 10:28 
GeneralRe: a question on heap..... Pin
Bob Stanneveld13-Jun-05 11:51
Bob Stanneveld13-Jun-05 11:51 
GeneralRe: a question on heap..... Pin
Toby Opferman14-Jun-05 12:46
Toby Opferman14-Jun-05 12:46 
GeneralRe: a question on heap..... Pin
Bob Stanneveld14-Jun-05 20:42
Bob Stanneveld14-Jun-05 20:42 
GeneralRe: a question on heap..... Pin
Toby Opferman9-Jun-05 19:14
Toby Opferman9-Jun-05 19:14 
QuestionWinsock2 -- recv() function query? Pin
arrya_amit3-May-05 19:45
arrya_amit3-May-05 19:45 
AnswerRe: Winsock2 -- recv() function query? Pin
DKT_3-May-05 20:29
DKT_3-May-05 20:29 
GeneralThe differences between &quot;class&quot; and &quot;struct&quot; in C++ Pin
inew3-May-05 19:25
inew3-May-05 19:25 
GeneralRe: The differences between &quot;class&quot; and &quot;struct&quot; in C++ Pin
Priyank Bolia3-May-05 19:30
Priyank Bolia3-May-05 19:30 
GeneralRe: The differences between &quot;class&quot; and &quot;struct&quot; in C++ Pin
S. Senthil Kumar3-May-05 20:35
S. Senthil Kumar3-May-05 20:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.