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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
/*
This file is part of Code_Saturne, a general-purpose CFD tool.
Copyright (C) 1998-2019 EDF S.A.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*----------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include "bft_error.h"
#include "bft_mem_usage.h"
#include "bft_mem.h"
static void
bft_mem_error_handler_test(const char *const file_name,
const int line_num,
const int sys_error_code,
const char *const format,
va_list arg_ptr)
{
CS_UNUSED(file_name);
CS_UNUSED(line_num);
CS_UNUSED(sys_error_code);
CS_UNUSED(format);
CS_UNUSED(arg_ptr);
fprintf(stderr, "test memory error handler (empty).\n");
}
int
main (int argc, char *argv[])
{
CS_UNUSED(argc);
CS_UNUSED(argv);
bft_error_handler_t *errhandler_save;
void *p1, *p2, *p3, *p4;
/* BFT initialization and environment */
bft_mem_usage_init();
bft_mem_init("bft_mem_log_file");
errhandler_save = bft_mem_error_handler_get();
bft_mem_error_handler_set(bft_mem_error_handler_test);
printf("test memory error handler set\n");
BFT_MALLOC(p1, 100000, long);
printf("p1 = %p\n", p1);
BFT_MALLOC(p2, 100000, double);
printf("p2 = %p\n", p2);
p3 = NULL;
BFT_REALLOC(p3, 100000, double);
printf("p3 = %p\n", p3);
BFT_REALLOC(p3, 10000, double);
printf("p3 = %p\n", p3);
BFT_MALLOC(p4, 5000000000, double);
printf("p4 = %p\n", p4);
printf("default memory error handler set\n");
bft_mem_error_handler_set(errhandler_save);
BFT_FREE(p1);
BFT_FREE(p2);
BFT_MALLOC(p2, 100000, double);
printf("p2 = %p\n", p2);
BFT_FREE(p2);
BFT_REALLOC(p3, 0, double);
printf("p3 = %p\n", p3);
if (bft_mem_have_memalign() == 1) {
void *pa;
BFT_MEMALIGN(pa, 128, 100, double);
printf("pa (aligned 128) = %p\n", pa);
BFT_FREE(pa);
}
bft_mem_end();
printf("max memory usage: %lu kB\n",
(unsigned long) bft_mem_usage_max_pr_size());
BFT_MALLOC(p1, 10000, long);
printf("p1 = %p\n", p1);
BFT_FREE(p1);
printf("p1 = %p\n", p1);
BFT_MALLOC(p1, 1000000000, double);
printf("p1 = %p\n", p1);
/* End */
exit (EXIT_SUCCESS);
}
|