@@ -8,6 +8,43 @@ extern "C" {
8
8
# error "this header requires Py_BUILD_CORE define"
9
9
#endif
10
10
11
+
12
+ /*
13
+ * Alignment of addresses returned to the user. 2 word alignment works
14
+ * on most current architectures (with 32-bit or 64-bit address buses).
15
+ * The alignment value is also used for grouping small requests in size
16
+ * classes spaced ALIGNMENT bytes apart.
17
+ *
18
+ * Don't change this. Lots of code implicitly relies on it.
19
+ */
20
+
21
+ #if SIZEOF_VOID_P > 4
22
+ #define ALIGNMENT 16 /* must be 2^N */
23
+ #define ALIGNMENT_SHIFT 4
24
+ #else
25
+ #define ALIGNMENT 8 /* must be 2^N */
26
+ #define ALIGNMENT_SHIFT 3
27
+ #endif
28
+
29
+
30
+ /*
31
+ * Max size threshold below which malloc requests are considered to be
32
+ * small enough in order to use freelists. You can tune
33
+ * this value according to your application behaviour and memory needs.
34
+ *
35
+ * Note: a size threshold of 512 guarantees that newly created dictionaries
36
+ * will be allocated from freelists or preallocated memory pools on 64-bit.
37
+ *
38
+ * The following invariants must hold:
39
+ * 1) ALIGNMENT <= SMALL_REQUEST_THRESHOLD <= 512
40
+ * 2) SMALL_REQUEST_THRESHOLD is evenly divisible by ALIGNMENT
41
+ *
42
+ * Although not required, for better performance and space efficiency,
43
+ * it is recommended that SMALL_REQUEST_THRESHOLD is set to a power of 2.
44
+ */
45
+ #define SMALL_REQUEST_THRESHOLD 512
46
+ #define NB_SMALL_SIZE_CLASSES (SMALL_REQUEST_THRESHOLD / ALIGNMENT)
47
+
11
48
# define PyTuple_MAXSAVESIZE 20 // Largest tuple to save on freelist
12
49
# define Py_tuple_MAXFREELIST 2000 // Maximum number of tuples of each size to save
13
50
# define Py_lists_MAXFREELIST 80
@@ -43,6 +80,7 @@ struct _Py_freelist {
43
80
};
44
81
45
82
struct _Py_freelists {
83
+ struct _Py_freelist by_size [NB_SMALL_SIZE_CLASSES ];
46
84
struct _Py_freelist floats ;
47
85
struct _Py_freelist ints ;
48
86
struct _Py_freelist tuples [PyTuple_MAXSAVESIZE ];
0 commit comments