Skip to content

Instantly share code, notes, and snippets.

@long-long-float
Created March 2, 2014 18:59
Show Gist options
  • Save long-long-float/9311734 to your computer and use it in GitHub Desktop.
Save long-long-float/9311734 to your computer and use it in GitHub Desktop.
memory leak(win32 api)
#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