vxx2 / vlib / v2_toberemoved / gen / cleanc / mem_darwin.c.v
22 lines · 18 sloc · 608 bytes · c0624b274a458fe3e487d89ae9554c2e8c25bdb6
Raw
1// Copyright (c) 2020-2024 Joe Conigliaro. All rights reserved.
2// Use of this source code is governed by an MIT license
3// that can be found in the LICENSE file.
4module cleanc
5
6#include <malloc/malloc.h>
7
8struct C.malloc_statistics_t {
9 blocks_in_use u32
10 size_in_use usize
11 max_size_in_use usize
12 size_allocated usize
13}
14
15fn C.malloc_default_zone() voidptr
16fn C.malloc_zone_statistics(zone voidptr, stats &C.malloc_statistics_t)
17
18fn darwin_cleanc_live_mb() u64 {
19 mut st := C.malloc_statistics_t{}
20 C.malloc_zone_statistics(C.malloc_default_zone(), &st)
21 return u64(st.size_in_use) / (1024 * 1024)
22}
23