diff options
Diffstat (limited to 'src/daemon/memorypool.h')
-rw-r--r-- | src/daemon/memorypool.h | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/daemon/memorypool.h b/src/daemon/memorypool.h new file mode 100644 index 00000000..c49e0d8e --- /dev/null +++ b/src/daemon/memorypool.h | |||
@@ -0,0 +1,87 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | (C) 2007 Daniel Pittman | ||
4 | |||
5 | libmicrohttpd is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libmicrohttpd is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libmicrohttpd; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file memorypool.h | ||
23 | * @brief memory pool; mostly used for efficient (de)allocation | ||
24 | * for each connection and bounding memory use for each | ||
25 | * request | ||
26 | * @author Christian Grothoff | ||
27 | */ | ||
28 | |||
29 | #ifndef MEMORYPOOL_H | ||
30 | #define MEMORYPOOL_H | ||
31 | |||
32 | #include "internal.h" | ||
33 | |||
34 | /** | ||
35 | * Opaque handle for a memory pool. | ||
36 | * Pools are not reentrant and must not be used | ||
37 | * by multiple threads. | ||
38 | */ | ||
39 | struct MemoryPool; | ||
40 | |||
41 | /** | ||
42 | * Create a memory pool. | ||
43 | * | ||
44 | * @param max maximum size of the pool | ||
45 | */ | ||
46 | struct MemoryPool * MHD_pool_create(unsigned int max); | ||
47 | |||
48 | /** | ||
49 | * Destroy a memory pool. | ||
50 | */ | ||
51 | void MHD_pool_destroy(struct MemoryPool * pool); | ||
52 | |||
53 | /** | ||
54 | * Allocate size bytes from the pool. | ||
55 | * | ||
56 | * @param from_end allocate from end of pool (set to MHD_YES); | ||
57 | * use this for small, persistent allocations that | ||
58 | * will never be reallocated | ||
59 | * @return NULL if the pool cannot support size more | ||
60 | * bytes | ||
61 | */ | ||
62 | void * MHD_pool_allocate(struct MemoryPool * pool, | ||
63 | unsigned int size, | ||
64 | int from_end); | ||
65 | |||
66 | /** | ||
67 | * Reallocate a block of memory obtained from the pool. | ||
68 | * This is particularly efficient when growing or | ||
69 | * shrinking the block that was last (re)allocated. | ||
70 | * If the given block is not the most recenlty | ||
71 | * (re)allocated block, the memory of the previous | ||
72 | * allocation may be leaked until the pool is | ||
73 | * destroyed (and copying the data maybe required). | ||
74 | * | ||
75 | * @param old the existing block | ||
76 | * @param old_size the size of the existing block | ||
77 | * @param new_size the new size of the block | ||
78 | * @return new address of the block, or | ||
79 | * NULL if the pool cannot support new_size | ||
80 | * bytes (old continues to be valid for old_size) | ||
81 | */ | ||
82 | void * MHD_pool_reallocate(struct MemoryPool * pool, | ||
83 | void * old, | ||
84 | unsigned int old_size, | ||
85 | unsigned int new_size); | ||
86 | |||
87 | #endif | ||