6e2ac8f326b80ba5d0272e88e26987b4fc102e40
4 * @brief Memory allocation with LEAK_DETECTION support
6 * Thread-save implementation
10 * Copyright (C) 2005 Jan Hutter, Martin Willi
11 * Hochschule fuer Technik Rapperswil
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
31 * Function to allocate a special type
33 * @param thing object on it a sizeof is performed
35 #define allocator_alloc_thing(thing) (allocator_alloc(sizeof(thing)))
39 * Allocates memory with LEAK_DETECTION and
40 * returns an empty data area filled with zeros
42 * @warning use this function not directly, only with assigned macros
43 * allocator_alloc and allocator_alloc_thing
45 * @param bytes number of bytes to allocate
46 * @param file filename from which the memory is allocated
47 * @param line line number in specific file
48 * @return allocated memory area
50 void * allocate(size_t bytes
, char * file
,int line
);
53 * Reallocates memory with LEAK_DETECTION and
54 * returns an empty data area filled with zeros
56 * @warning use this function not directly, only with assigned macro
59 * @param old pointer to the old data area
60 * @param bytes number of bytes to allocate
61 * @param file filename from which the memory is allocated
62 * @param line line number in specific file
63 * @return reallocated memory area
65 void * reallocate(void * old
, size_t bytes
, char * file
, int line
);
67 * Frees memory with LEAK_DETECTION
69 * @warning use this function not directly, only with assigned macro
72 * @param pointer pointer to the data area to free
74 void free_pointer(void * pointer
);
76 #define allocator_alloc(bytes) (allocate(bytes,__FILE__,__LINE__))
77 #define allocator_realloc(old,bytes) (reallocate(old,bytes,__FILE__, __LINE__))
78 #define allocator_free(pointer) (free_pointer(pointer))
81 * Report memory leaks to stderr
83 void report_memory_leaks(void);
85 #define allocator_alloc(bytes) (malloc(bytes))
86 #define allocator_realloc(old,bytes) (realloc(old,bytes))
87 #define allocator_free(pointer) (free(pointer))
88 #define report_memory_leaks(void) {}
91 #endif /*ALLOCATOR_H_*/