Esempio n. 1
0
        public Limit(ulong ProcessMemoryLimit, ulong JobMemoryLimit)
        {
            handle = CreateJobObject(IntPtr.Zero, null);

            var basicInfo = new JOBOBJECT_BASIC_LIMIT_INFORMATION
            {
                LimitFlags = (UInt32)LimitFlags.JOB_OBJECT_LIMIT_JOB_MEMORY,
            };

            var extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION
            {
                BasicLimitInformation = basicInfo,
                ProcessMemoryLimit    = new UIntPtr(ProcessMemoryLimit),
                JobMemoryLimit        = new UIntPtr(JobMemoryLimit),
            };

            int    length          = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
            IntPtr extendedInfoPtr = Marshal.AllocHGlobal(length);

            Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false);

            if (!SetInformationJobObject(handle, JobObjectInfoType.ExtendedLimitInformation, extendedInfoPtr, (uint)length))
            {
                throw new Exception(string.Format("Unable to set information.  Error: {0}", Marshal.GetLastWin32Error()));
            }
        }
Esempio n. 2
0
File: Limit.cs Progetto: vokac/F2B
        public Limit(ulong ProcessMemoryLimit, ulong JobMemoryLimit)
        {
            handle = CreateJobObject(IntPtr.Zero, null);

            var basicInfo = new JOBOBJECT_BASIC_LIMIT_INFORMATION
            {
                LimitFlags = (UInt32)LimitFlags.JOB_OBJECT_LIMIT_JOB_MEMORY,
            };

            var extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION
            {
                BasicLimitInformation = basicInfo,
                ProcessMemoryLimit = new UIntPtr(ProcessMemoryLimit),
                JobMemoryLimit = new UIntPtr(JobMemoryLimit),
            };

            int length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
            IntPtr extendedInfoPtr = Marshal.AllocHGlobal(length);
            Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false);

            if (!SetInformationJobObject(handle, JobObjectInfoType.ExtendedLimitInformation, extendedInfoPtr, (uint)length))
            {
                throw new Exception(string.Format("Unable to set information.  Error: {0}", Marshal.GetLastWin32Error()));
            }
        }