Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created June 19, 2018 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/1f60d7ddad1e85d57f39d100661fabaf to your computer and use it in GitHub Desktop.
Save miguelmota/1f60d7ddad1e85d57f39d100661fabaf to your computer and use it in GitHub Desktop.
C++ allocate lots of memory (for testing)
#include <iostream>
#include <new>
#include <cstdlib>
int main()
{
int i=0;
char* ptr =NULL;
while(i<50){
if ((ptr =(char*)malloc(1048576)) == NULL) {///1MB allocated
std::cout << "Allocation fails at " << i << "MB\n";
return 0;
}
std::cout << "Allocated "<< i+1 << "MB\n";
i++;
}
std::cout << "Finished allocation";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment