Use shorts for chunk sizes when possible.
[polipo.git] / chunk.h
blob9a20fd717b749229c203e9a66f3e8fb85a9143ef
1 /*
2 Copyright (c) 2003-2006 by Juliusz Chroboczek
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
23 /* A larger chunk size gets you better I/O throughput, at the cost of
24 higer memory usage. We assume you've got plenty of memory if you've
25 got 64-bit longs. */
27 #ifndef CHUNK_SIZE
28 #ifdef ULONG_MAX
29 #if ULONG_MAX > 4294967295UL
30 #define CHUNK_SIZE (8 * 1024)
31 #else
32 #define CHUNK_SIZE (4 * 1024)
33 #endif
34 #else
35 #warn "ULONG_MAX not defined -- using 4kB chunks"
36 #define CHUNK_SIZE (4 * 1024)
37 #endif
38 #endif
40 #define CHUNKS(bytes) ((bytes) / CHUNK_SIZE)
42 extern int chunkLowMark, chunkHighMark, chunkCriticalMark;
43 extern int used_chunks;
45 void preinitChunks(void);
46 void initChunks(void);
47 void *get_chunk(void) ATTRIBUTE ((malloc));
48 void *maybe_get_chunk(void) ATTRIBUTE ((malloc));
50 void dispose_chunk(void *chunk);
51 void free_chunk_arenas(void);
52 int totalChunkArenaSize(void);