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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//! ort: Open Router CLI
//! https://github.com/grahamking/ort
//!
//! MIT License
//! Copyright (c) 2025 Graham King
//!
//! Arena allocator. No heap allocations for entire program run.
//! We statically allocate a large chunk of memory (`.bss` segment),
//! and use that to fill allocation requests. This avoids doing
//! any syscalls to get memory.
use Layout;
use c_void;
use ;
use cratesyscall;
static mut IS_FIRST_REALLOC: bool = true;
use crateto_ascii;
/// All allocated memory locations will have this alignment, max_align_t
const ALIGN: usize = 16;
// How much memory to allocate total. Don't exceed this!
//const MEM_SIZE: usize = 2 * 1024 * 1024;
// In debug mode to print panics, need > 8MiB
const MEM_SIZE: usize = 16 * 1024 * 1024;
;
static mut HEAP: Heap = Heap;
static mut OFFSET: AtomicUsize = new;
;
// In case you were wondering, yes all three methods get used. Rust does
// a bnuch of alloc_zeroed and realloc.
//
// Build with feature "print-allocations" to see memory being allocated:
// cargo build --features="print-allocations"
// cargo build --release --features="print-allocations" -Zbuild-std="core,alloc"
//
// There's a Python script at the end of this file to summarize the output.
//
// Normal / prompt usage seems to peak under 64 Kib of active memory.
//
// `ort list` peaks around 180 Kib because it has one large (~128 KiB)
// allocation which is a string holding the names of all models, so we can sort them.
unsafe
/*
"""Print running totals from allocs.txt and report the maximum cumulative value."""
from pathlib import Path
def main() -> None:
path = Path("allocs.txt")
if not path.is_file():
raise SystemExit("allocs.txt not found in the current directory")
total = 0
max_total = None # Highest cumulative total
max_plus = None # Largest individual + value
max_minus = None # Largest (most negative) individual - value
with path.open() as fh:
for raw_line in fh:
line = raw_line.strip()
if not line:
continue # Skip blank lines silently
try:
delta = int(line)
except ValueError as exc:
raise SystemExit(f"Invalid line in allocs.txt: {line!r}") from exc
# realloc indicators
line = line.replace('/', '+').replace('\\', '-')
if delta > 0:
max_plus = delta if max_plus is None else max(max_plus, delta)
elif delta < 0:
max_minus = delta if max_minus is None else min(max_minus, delta)
total += delta
max_total = total if max_total is None else max(max_total, total)
print(f"{line} {total}")
print() # Blank line before the summary, matching the example
print(f"Max: {max_total if max_total is not None else 0}")
print(f"Largest +: {max_plus if max_plus is not None else 0}")
print(f"Largest -: {max_minus if max_minus is not None else 0}")
if __name__ == "__main__":
main()
*/