Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / callgrind / costs.c
blob936cf9014275240f4ffd79105b05bc51b2f8e837
1 /*--------------------------------------------------------------------*/
2 /*--- Callgrind ---*/
3 /*--- ct_costs.c ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Callgrind, a Valgrind tool for call tracing.
9 Copyright (C) 2002-2017, Josef Weidendorfer (Josef.Weidendorfer@gmx.de)
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, see <http://www.gnu.org/licenses/>.
24 The GNU General Public License is contained in the file COPYING.
27 #include "global.h"
29 #include "pub_tool_mallocfree.h"
31 #define COSTCHUNK_SIZE 100000
33 UInt CLG_(costarray_entries) = 0;
34 UInt CLG_(costarray_chunks) = 0;
35 static CostChunk* cost_chunk_base = 0;
36 static CostChunk* cost_chunk_current = 0;
38 ULong* CLG_(get_costarray)(Int size)
40 ULong* ptr;
42 if (!cost_chunk_current ||
43 (cost_chunk_current->size - cost_chunk_current->used < size)) {
44 CostChunk* cc = (CostChunk*) CLG_MALLOC("cl.costs.gc.1",
45 sizeof(CostChunk) +
46 COSTCHUNK_SIZE * sizeof(ULong));
47 CLG_ASSERT(size < COSTCHUNK_SIZE);
49 cc->size = COSTCHUNK_SIZE;
50 cc->used = 0;
51 cc->next = 0;
53 if (cost_chunk_current)
54 cost_chunk_current->next = cc;
55 cost_chunk_current = cc;
57 if (!cost_chunk_base) cost_chunk_base = cc;
59 CLG_(costarray_chunks)++;
62 ptr = &(cost_chunk_current->data[cost_chunk_current->used]);
63 cost_chunk_current->used += size;
65 CLG_(costarray_entries) += size;
67 return ptr;