Created
March 2, 2014 18:59
-
-
Save long-long-float/9311734 to your computer and use it in GitHub Desktop.
memory leak(win32 api)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <cstring> | |
#include <vector> | |
#include <cstdlib> | |
#include <ctime> | |
#include <iostream> | |
using namespace std; | |
int main(int argc, char const *argv[]){ | |
while(true) { | |
Sleep(1000); | |
const unsigned size = 1024 * 1024; //MB | |
char *buf; | |
try{ | |
buf = (char*)VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE | PAGE_NOCACHE); | |
if(!buf) throw; | |
} catch(...) { | |
cerr << "bat alloc!" << endl; | |
continue; | |
} | |
FillMemory(buf, size, -1); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment