Sun, 21 Jan 2018 14:10:59 +0100
fixes return value for multiplication with zero in ucx_szmul
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
1 | /* |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
3 | * |
259 | 4 | * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
5 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
8 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
11 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
15 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
27 | */ |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
28 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
29 | * Allocator for custom memory management. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
30 | * |
225
a1a068c2c4ef
updates documenting comments
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
31 | * A UCX allocator consists of a pointer to the memory area / pool and four |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
32 | * function pointers to memory management functions operating on this memory |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
33 | * area / pool. These functions shall behave equivalent to the standard libc |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
34 | * functions <code>malloc(), calloc(), realloc()</code> and <code>free()</code>. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
35 | * |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
36 | * The signature of the memory management functions is based on the signature |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
37 | * of the respective libc function but each of them takes the pointer to the |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
38 | * memory area / pool as first argument. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
39 | * |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
40 | * As the pointer to the memory area / pool can be arbitrarily chosen, any data |
225
a1a068c2c4ef
updates documenting comments
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
41 | * can be provided to the memory management functions. A UcxMempool is just |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
42 | * one example. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
43 | * |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
44 | * @see mempool.h |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
45 | * @see UcxMap |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
46 | * |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
47 | * @file allocator.h |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
48 | * @author Mike Becker |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
49 | * @author Olaf Wintermann |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
50 | */ |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
51 | |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
52 | #ifndef UCX_ALLOCATOR_H |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
53 | #define UCX_ALLOCATOR_H |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
54 | |
259 | 55 | #include "ucx.h" |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
56 | |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
57 | #ifdef __cplusplus |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
58 | extern "C" { |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
59 | #endif |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
60 | |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
61 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
62 | * A function pointer to the allocators <code>malloc()</code> function. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
63 | * @see UcxAllocator |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
64 | */ |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
65 | typedef void*(*ucx_allocator_malloc)(void *pool, size_t n); |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
66 | |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
67 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
68 | * A function pointer to the allocators <code>calloc()</code> function. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
69 | * @see UcxAllocator |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
70 | */ |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
71 | typedef void*(*ucx_allocator_calloc)(void *pool, size_t n, size_t size); |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
72 | |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
73 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
74 | * A function pointer to the allocators <code>realloc()</code> function. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
75 | * @see UcxAllocator |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
76 | */ |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
77 | typedef void*(*ucx_allocator_realloc)(void *pool, void *data, size_t n); |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
78 | |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
79 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
80 | * A function pointer to the allocators <code>free()</code> function. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
81 | * @see UcxAllocator |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
82 | */ |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
83 | typedef void(*ucx_allocator_free)(void *pool, void *data); |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
84 | |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
85 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
86 | * UCX allocator data structure containing memory management functions. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
87 | */ |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
88 | typedef struct { |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
89 | /** Pointer to an area of memory or a complex memory pool. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
90 | * This pointer will be passed to any memory management function as first |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
91 | * argument. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
92 | */ |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
93 | void *pool; |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
94 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
95 | * The <code>malloc()</code> function for this allocator. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
96 | */ |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
97 | ucx_allocator_malloc malloc; |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
98 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
99 | * The <code>calloc()</code> function for this allocator. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
100 | */ |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
101 | ucx_allocator_calloc calloc; |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
102 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
103 | * The <code>realloc()</code> function for this allocator. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
104 | */ |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
105 | ucx_allocator_realloc realloc; |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
106 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
107 | * The <code>free()</code> function for this allocator. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
108 | */ |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
109 | ucx_allocator_free free; |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
110 | } UcxAllocator; |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
111 | |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
112 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
113 | * Returns a pointer to the default allocator. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
114 | * |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
115 | * The default allocator contains wrappers to the standard libc memory |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
116 | * management functions. Use this function to get a pointer to a globally |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
117 | * available allocator. You may also define an own UcxAllocator by assigning |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
118 | * #UCX_ALLOCATOR_DEFAULT to a variable and pass the address of this variable |
225
a1a068c2c4ef
updates documenting comments
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
119 | * to any function that takes a UcxAllocator as argument. Note that using |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
120 | * this function is the recommended way of passing a default allocator, thus |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
121 | * it never runs out of scope. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
122 | * |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
123 | * @return a pointer to the default allocator |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
124 | * |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
125 | * @see UCX_ALLOCATOR_DEFAULT |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
126 | */ |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
127 | UcxAllocator *ucx_default_allocator(); |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
128 | |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
129 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
130 | * A wrapper for the standard libc <code>malloc()</code> function. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
131 | * @param ignore ignored (may be used by allocators for pooled memory) |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
132 | * @param n argument passed to <code>malloc()</code> |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
133 | * @return return value of <code>malloc()</code> |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
134 | */ |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
135 | void *ucx_default_malloc(void *ignore, size_t n); |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
136 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
137 | * A wrapper for the standard libc <code>calloc()</code> function. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
138 | * @param ignore ignored (may be used by allocators for pooled memory) |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
139 | * @param n argument passed to <code>calloc()</code> |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
140 | * @param size argument passed to <code>calloc()</code> |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
141 | * @return return value of <code>calloc()</code> |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
142 | */ |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
143 | void *ucx_default_calloc(void *ignore, size_t n, size_t size); |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
144 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
145 | * A wrapper for the standard libc <code>realloc()</code> function. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
146 | * @param ignore ignored (may be used by allocators for pooled memory) |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
147 | * @param data argumend passed to <code>realloc()</code> |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
148 | * @param n argument passed to <code>realloc()</code> |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
149 | * @return return value of <code>realloc()</code> |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
150 | */ |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
151 | void *ucx_default_realloc(void *ignore, void *data, size_t n); |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
152 | /** |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
153 | * A wrapper for the standard libc <code>free()</code> function. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
154 | * @param ignore ignored (may be used by allocators for pooled memory) |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
155 | * @param data argument passed to <code>free()</code> |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
156 | */ |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
157 | void ucx_default_free(void *ignore, void *data); |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
158 | |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
159 | /** |
173
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
160 | * Shorthand for calling an allocators malloc function. |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
161 | * @param allocator the allocator to use |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
162 | * @param n size of space to allocate |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
163 | * @return a pointer to the allocated memory area |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
164 | */ |
174
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
165 | #define almalloc(allocator, n) ((allocator)->malloc((allocator)->pool, n)) |
173
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
166 | |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
167 | /** |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
168 | * Shorthand for calling an allocators calloc function. |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
169 | * @param allocator the allocator to use |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
170 | * @param n the count of elements the space should be allocated for |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
171 | * @param size the size of each element |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
172 | * @return a pointer to the allocated memory area |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
173 | */ |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
174 | #define alcalloc(allocator, n, size) \ |
174
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
175 | ((allocator)->calloc((allocator)->pool, n, size)) |
173
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
176 | |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
177 | /** |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
178 | * Shorthand for calling an allocators realloc function. |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
179 | * @param allocator the allocator to use |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
180 | * @param ptr the pointer to the memory area that shall be reallocated |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
181 | * @param n the new size of the allocated memory area |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
182 | * @return a pointer to the reallocated memory area |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
183 | */ |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
184 | #define alrealloc(allocator, ptr, n) \ |
174
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
185 | ((allocator)->realloc((allocator)->pool, ptr, n)) |
173
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
186 | |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
187 | /** |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
188 | * Shorthand for calling an allocators free function. |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
189 | * @param allocator the allocator to use |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
190 | * @param ptr the pointer to the memory area that shall be freed |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
191 | */ |
174
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
192 | #define alfree(allocator, ptr) ((allocator)->free((allocator)->pool, ptr)) |
173
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
193 | |
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
194 | /** |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
195 | * Convenient macro for a default allocator <code>struct</code> definition. |
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
196 | */ |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
197 | #define UCX_ALLOCATOR_DEFAULT {NULL, \ |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
198 | ucx_default_malloc, ucx_default_calloc, ucx_default_realloc, \ |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
199 | ucx_default_free } |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
200 | |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
201 | #ifdef __cplusplus |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
202 | } |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
203 | #endif |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
204 | |
118
151f5345f303
documented allocator + some further documentation for sstr_t
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
205 | #endif /* UCX_ALLOCATOR_H */ |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
206 |