-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
darwin: implement node:os.freemem() (#12870)
- Loading branch information
Showing
3 changed files
with
28 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "root.h" | ||
|
||
#if OS(DARWIN) | ||
#include <mach/vm_types.h> | ||
#include <mach/mach_host.h> | ||
#include <mach/mach_init.h> | ||
#include <mach/message.h> | ||
#include <mach/vm_statistics.h> | ||
#include <unistd.h> | ||
|
||
// Adapted from libuv darwin uv_get_free_memory, MIT | ||
extern "C" uint64_t Bun__Os__getFreeMemory(void) | ||
{ | ||
vm_statistics_data_t info; | ||
mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t); | ||
|
||
if (host_statistics(mach_host_self(), HOST_VM_INFO, | ||
(host_info_t)&info, &count) | ||
!= KERN_SUCCESS) { | ||
return 0; | ||
} | ||
|
||
return (uint64_t)info.free_count * sysconf(_SC_PAGESIZE); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters