CAEN Utility  2.0.2
Utilities for CAEN projects
CAENAllocator.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * CAEN SpA - Software Division
4 * Via Vetraia, 11 - 55049 - Viareggio ITALY
5 * +39 0594 388 398 - www.caen.it
6 *
7 *******************************************************************************
8 *
9 * Copyright (C) 2019-2022 CAEN SpA
10 *
11 * This file is part of the CAEN Utility.
12 *
13 * The CAEN Utility is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 3 of the License, or (at your option) any later version.
17 *
18 * The CAEN Utility is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with the CAEN Utility; if not, see
25 * https://www.gnu.org/licenses/.
26 *
27 * SPDX-License-Identifier: LGPL-3.0-or-later
28 *
29 ******************************************************************************
30 *
31 * \file CAENAllocator.h
32 * \brief Utilities to handle memory allocation in C minimizing memory leaks
33 * \author Francesco Pepe
34 *
35 ******************************************************************************/
36 
37 #ifndef CAEN_INCLUDE_CAENALLOCATOR_H_
38 #define CAEN_INCLUDE_CAENALLOCATOR_H_
39 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 #include <stdint.h>
58 
60 #include <CAENUtility.h>
61 
68 
80 
89 
98 CAEN_UTILITY_DLLAPI void* CAEN_UTILITY_API c_allocator_calloc(c_allocator_t* allocator, size_t nmemb, size_t size);
99 
100 // TODO: realloc: search the list for an element and realloc it if found. Manage pointer changes and case of new allocation.
101 
109 
120 
126 
137 
143 
153 #define c_allocator_freeall_and_return(A, R) (c_allocator_freeall(A), R)
154 
155 // TODO: free a single element: search the linkedlist for such element, free and remove it from list
156 
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 #endif // CAEN_INCLUDE_CAENALLOCATOR_H_
#define c_attribute_alloc_size(...)
Definition: CAENUtility.h:183
#define CAEN_UTILITY_API
Definition: CAENUtility.h:104
Main header and generic tools.
void c_allocator_free(c_allocator_t *allocator, void *ptr)
void * c_allocator_malloc(c_allocator_t *allocator, size_t size)
Definition: CAENAllocator.c:86
#define CAEN_UTILITY_DLLAPI
Definition: CAENUtility.h:105
c_allocator_t c_allocator_create()
Definition: CAENAllocator.c:42
#define c_nodiscard
Definition: CAENUtility.h:245
#define c_attribute_malloc
Definition: CAENUtility.h:199
#define c_declspec_allocator
Definition: CAENUtility.h:191
void(* c_resource_destroy_function)(void *)
void c_allocator_clear(c_allocator_t *allocator)
void c_allocator_release(c_allocator_t *allocator, void *ptr)
int32_t c_allocator_error_count(const c_allocator_t *allocator)
Definition: CAENAllocator.c:94
void c_allocator_freeall(c_allocator_t *allocator)
void * c_allocator_resource_create(c_allocator_t *allocator, c_resource_destroy_function df, void *resource)
Definition: CAENAllocator.c:54
void * c_allocator_calloc(c_allocator_t *allocator, size_t nmemb, size_t size)
Definition: CAENAllocator.c:90