mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Research: Add badalloc
This commit is contained in:
parent
a42da57448
commit
44e550e523
2 changed files with 28 additions and 0 deletions
11
trunk/research/frame/bad_alloc0.cpp
Normal file
11
trunk/research/frame/bad_alloc0.cpp
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
ulimit -S -v 204800
|
||||||
|
g++ -g -O0 bad_alloc0.cpp -o bad_alloc && ./bad_alloc
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
int main(){
|
||||||
|
char* p1 = new char[193000 * 1024]; // huge allocation
|
||||||
|
char* p0 = new char[100 * 1024]; // small allocation
|
||||||
|
printf("OK\n");
|
||||||
|
}
|
||||||
|
|
17
trunk/research/frame/bad_alloc1.cpp
Normal file
17
trunk/research/frame/bad_alloc1.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
ulimit -S -v 204800
|
||||||
|
g++ -g -O0 bad_alloc1.cpp -o bad_alloc && ./bad_alloc
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <new>
|
||||||
|
void handler() {
|
||||||
|
printf("Memory allocate failed\n");
|
||||||
|
std::set_new_handler(NULL); // New will try to alloc again, then abort.
|
||||||
|
}
|
||||||
|
int main(){
|
||||||
|
std::set_new_handler(handler);
|
||||||
|
char* p1 = new char[193000 * 1024]; // huge allocation
|
||||||
|
char* p0 = new char[100 * 1024]; // small allocation
|
||||||
|
printf("OK\n");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue