Skip to content

Commit 9492937

Browse files
committed
add macos switch for totalSystemMemory
1 parent cf90a5e commit 9492937

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/std/process.zig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,18 @@ pub fn totalSystemMemory() TotalSystemMemoryError!u64 {
17641764
};
17651765
return @as(usize, @intCast(physmem));
17661766
},
1767+
.macos => {
1768+
// "hw.memsize" returns uint64_t
1769+
var physmem: u64 = undefined;
1770+
var len: usize = @sizeOf(u64);
1771+
posix.sysctlbynameZ("hw.memsize", &physmem, &len, null, 0) catch |err| switch (err) {
1772+
error.PermissionDenied => unreachable, // only when setting values,
1773+
error.SystemResources => unreachable, // memory already on the stack
1774+
error.UnknownName => unreachable, // constant, known good value
1775+
else => return error.UnknownTotalSystemMemory,
1776+
};
1777+
return @as(u64, @intCast(physmem));
1778+
},
17671779
.openbsd => {
17681780
const mib: [2]c_int = [_]c_int{
17691781
posix.CTL.HW,

0 commit comments

Comments
 (0)