1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
/*
============================================================================
Name : source.c
Date : 19/02/2017
Author : SAMBIA39
Version : 0.1
Copyright : Copyright © 2017 SAMBIA39 All rights reserved.
Description : Ansi-style
============================================================================
*/
#define BLOCMEM 50000 /* nombre de bloc memoire */
#define GIGAOCT 1024*1024*1024 /* 1Go par bloc mémoire */
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <stddef.h>
#include <string.h>
int main( void ){
extern int errno; /* Errno */
char *pMem[BLOCMEM]; /* Bloc mémoires */
unsigned long i = 0; /* Variable d'incrémentation */
/*
* Allocation des 50.000 blocs
* mémoire de 1Go pas en une seul fois
*/
errno = 0;
for( i = 0; i < BLOCMEM; i++ ){
if( NULL == ( pMem[i] = malloc(GIGAOCT)) ){
fprintf( stdout, "(%d)\t%s\n\t:%s\n",
errno, "Erreur alloc mem", strerror(errno) );
return (EXIT_FAILURE);
}
}
fprintf( stdout, "Fin d'Allocation de %d\n", BLOCMEM );
/*
* Tentative d'écriture mémoire
*/
for( i = 0; i < BLOCMEM; i++ ){
memset( pMem[i], 0, GIGAOCT );
fprintf( stdout, "(%ld)[%p]\t:%s\t%ld Go utiliser\n", i,(void*)pMem[i],
(NULL == pMem[i]) ? "NULL":"Initialisé à 0 et", (i+1) );
}
/*
* Free bloc mémoire jamais atteint
* OOM-Kiler actifs
*/
for( i = 0; i < BLOCMEM; i++ ){
free( pMem[i] );
pMem[i] = NULL;
}
return (EXIT_SUCCESS);
} |
Partager