Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BLI_temporary_allocator.h « blenlib « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b378e5869c0b6defcce60edcb8ecf0ce4523c936 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

/** \file
 * \ingroup bli
 *
 * This allocation method assumes
 *   1. The allocations are short-lived.
 *   2. The total number of allocations is bound by a constant per thread.
 *
 * These two assumptions make it possible to cache and reuse relatively large buffers. They allow
 * to hand out buffers that are much larger than the requested size, without the fear of running
 * out of memory.
 *
 * The assumptions might feel a bit limiting at first, but hold true in many cases. For example,
 * many algorithms need to store temporary data. With this allocator, the allocation can become
 * very cheap for common cases.
 *
 * Many cpu-bound algorithms can benefit from being split up into several stages, whereby the
 * output of one stage is written into an array that is read by the next stage. This makes them
 * easier to debug, profile and optimize. Often a reason this is not done is that the memory
 * allocation might be expensive. The goal of this allocator is to make this a non-issue, by
 * reusing the same long buffers over and over again.
 *
 * All allocated buffers are 64 byte aligned, to make them as reusable as possible.
 * If the requested size is too large, there is a fallback to normal allocation. The allocation
 * overhead is probably very small in these cases anyway.
 *
 * The best way to use this allocator is to use one of the prepared containers like TemporaryVector
 * and TemporaryArray.
 */

#ifndef __BLI_TEMPORARY_ALLOCATOR_H__
#define __BLI_TEMPORARY_ALLOCATOR_H__

#include "BLI_utildefines.h"

#ifdef __cplusplus
extern "C" {
#endif

#define BLI_TEMPORARY_BUFFER_ALIGNMENT 64

void *BLI_temporary_allocate(uint size);
void BLI_temporary_deallocate(void *buffer);

#ifdef __cplusplus
}
#endif

#endif /* __BLI_TEMPORARY_ALLOCATOR_H__ */