2
This file is part of Code_Saturne, a general-purpose CFD tool.
4
Copyright (C) 1998-2011 EDF S.A.
6
This program is free software; you can redistribute it and/or modify it under
7
the terms of the GNU General Public License as published by the Free Software
8
Foundation; either version 2 of the License, or (at your option) any later
11
This program is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
You should have received a copy of the GNU General Public License along with
17
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
18
Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
/*----------------------------------------------------------------------------*/
31
#include "bft_error.h"
32
#include "bft_mem_usage.h"
34
#include "bft_sys_info.h"
37
bft_mem_error_handler_test(const char *const file_name,
39
const int sys_error_code,
40
const char *const format,
43
fprintf(stderr, "test memory error handler (empty).\n");
47
main (int argc, char *argv[])
49
bft_error_handler_t *errhandler_save;
51
void *p1, *p2, *p3, *p4;
53
/* BFT initialization and environment */
57
bft_mem_init("bft_mem_log_file");
59
errhandler_save = bft_mem_error_handler_get();
61
bft_mem_error_handler_set(bft_mem_error_handler_test);
62
printf("test memory error handler set\n");
64
BFT_MALLOC(p1, 100000, long);
65
printf("p1 = %p\n", p1);
66
BFT_MALLOC(p2, 100000, double);
67
printf("p2 = %p\n", p2);
70
BFT_REALLOC(p3, 100000, double);
71
printf("p3 = %p\n", p3);
72
BFT_REALLOC(p3, 10000, double);
73
printf("p3 = %p\n", p3);
75
BFT_MALLOC(p4, 5000000000, double);
76
printf("p4 = %p\n", p4);
78
printf("default memory error handler set\n");
79
bft_mem_error_handler_set(errhandler_save);
83
BFT_MALLOC(p2, 100000, double);
84
printf("p2 = %p\n", p2);
86
BFT_REALLOC(p3, 0, double);
87
printf("p3 = %p\n", p3);
89
if (bft_mem_have_memalign() == 1) {
91
BFT_MEMALIGN(pa, 128, 100, double);
92
printf("pa (aligned 128) = %p\n", pa);
98
printf("max memory usage: %lu kB\n",
99
(unsigned long) bft_mem_usage_max_pr_size());
101
BFT_MALLOC(p1, 10000, long);
102
printf("p1 = %p\n", p1);
104
printf("p1 = %p\n", p1);
105
BFT_MALLOC(p1, 1000000000, double);
106
printf("p1 = %p\n", p1);