2
0
Nicolas Cannasse 1 жил өмнө
parent
commit
5185f82e79
1 өөрчлөгдсөн 15 нэмэгдсэн , 1 устгасан
  1. 15 1
      src/std/sys.c

+ 15 - 1
src/std/sys.c

@@ -39,6 +39,7 @@
 #	include <conio.h>
 #	include <fcntl.h>
 #	include <io.h>
+#	include <psapi.h>
 #	define getenv _wgetenv
 #	define putenv _wputenv
 #	define getcwd(buf,size) (void*)(int_val)GetCurrentDirectoryW(size,buf)
@@ -607,6 +608,18 @@ HL_PRIM vbyte *hl_sys_exe_path() {
 #endif
 }
 
+HL_PRIM double hl_sys_process_memory() {
+#if defined(HL_WIN)
+	PROCESS_MEMORY_COUNTERS inf;
+	GetProcessMemoryInfo(GetCurrentProcess(),&inf,sizeof(inf));
+	return (double)inf.WorkingSetSize;
+#elif defined(HL_CONSOLE)
+	return sys_process_memory();
+#else
+	return 0.;
+#endif
+}
+
 HL_PRIM int hl_sys_get_char( bool b ) {
 #	if defined(HL_WIN_DESKTOP)
 	return b?getche():getch();
@@ -717,4 +730,5 @@ DEFINE_PRIM(_I32, sys_getpid, _NO_ARG);
 DEFINE_PRIM(_BOOL, sys_check_reload, _BYTES);
 DEFINE_PRIM(_VOID, sys_profile_event, _I32 _BYTES _I32);
 DEFINE_PRIM(_I32, sys_set_flags, _I32);
-DEFINE_PRIM(_BOOL, sys_has_debugger, _NO_ARG);
+DEFINE_PRIM(_BOOL, sys_has_debugger, _NO_ARG);
+DEFINE_PRIM(_F64, sys_process_memory, _NO_ARG);