Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
proclimits.h
Go to the documentation of this file.
1// proclimits.h must be included in .cpp file
2// only after #if[n]def _RWSTD_NO_SETRLIMIT line
3
4
26#if !defined (_RWSTD_NO_SETRLIMIT)
27
28# include <sys/resource.h> // for setrlimit()
29
30void limit_memory (unsigned long limit)
31{
32 struct rlimit rl = { limit, limit };
33 setrlimit (RLIMIT_DATA, &rl);
34}
35
36#elif defined (_WIN32)
37
38# ifndef _WIN32_WINNT
39# define _WIN32_WINNT 0x0500
40# endif
41
42# if _WIN32_WINNT >= 0x0500
43
44// Job Objects available only in Windows 2000 and later
45
46# include <windows.h>
47
48void limit_memory (unsigned long limit)
49{
50 SYSTEM_INFO info;
51 GetSystemInfo (&info);
52
53 HANDLE hJob = CreateJobObject (NULL, NULL);
54 if (hJob) {
55 if (AssignProcessToJobObject (hJob, GetCurrentProcess ())) {
56 JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = { 0 };
57 job_info.BasicLimitInformation.LimitFlags =
58 JOB_OBJECT_LIMIT_PROCESS_MEMORY;
59 job_info.ProcessMemoryLimit =
60 limit > info.dwPageSize ? limit : info.dwPageSize;
61 SetInformationJobObject (hJob,
62 JobObjectExtendedLimitInformation,
63 &job_info, sizeof (job_info));
64 }
65 CloseHandle (hJob);
66 }
67}
68
69# else // _WIN32_WINNT < 0x0500
70
71void limit_memory (unsigned long) { /* no-op */ }
72
73# endif // _WIN32_WINNT
74
75#else // _RWSTD_NO_SETRLIMIT && !_WIN32
76
77void limit_memory (unsigned long) { /* no-op */ }
78
79#endif // _RWSTD_NO_SETRLIMIT
#define NULL
std::ostream & info() noexcept
replacement for std::cout for NeBuild logging.
Definition Config.h:69
void limit_memory(unsigned long limit)
Definition proclimits.h:30