rickyrick2000

stupid malloc

Sep 12th, 2022 (edited)
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5.  
  6. #define BUFSIZE 1073741824 //1GiB
  7.  
  8. int main(){
  9.     printf("start\n");
  10.     printf("%lu \n", sizeof(u_int32_t));
  11.     for(size_t i = 0; i < (BUFSIZE / 4); i++){
  12.         u_int32_t* p = malloc(sizeof(u_int32_t));
  13.         if (p == NULL){
  14.             printf("alloc failed\n");
  15.             exit(1);
  16.         }
  17.     } //eats around 8GiB
  18.     sleep(15);
  19.     printf("exit\n");
  20. }
Advertisement
Add Comment
Please, Sign In to add comment