What's the correct way to use QueryInformationJobObject ? #869
Replies: 1 comment 1 reply
-
What example is this? Is it per chance this one?
Only if the second argument is
Yes. You're doing manual memory management. Ugh. Much harder than necessary. But props to you for using try/finally to guard against memory leaks. But it isn't necessary with the easier way. static unsafe int GetMemoryCap(HANDLE jobHandle)
{
JOBOBJECT_EXTENDED_LIMIT_INFORMATION result = default;
BOOL isCallSuccessful = QueryInformationJobObject(jobHandle, JOBOBJECTINFOCLASS.JobObjectExtendedLimitInformation, &result, (uint)sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION), null);
if (!isCallSuccessful)
{
throw new Win32Exception();
}
return (int)result.JobMemoryLimit;
} See how instead of allocating unmanaged memory and then copying data around, we just point directly at our local struct on the stack. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was playing with the ProcessJobTracker example class to add a method that can query the job object and I have two questions:
(a) I suppose the third parameter of QueryInformationJobObject should be a pointer that points to a block of of memory the size of JOBOBJECT_EXTENDED_LIMIT_INFORMATION. - Is my understanding correct ?
(2) I created a job object with
And here is the method I use to get the job memory limit. It seems to work fine mand give me the expected result, but I wanted to know if there is a better way to do this?
Beta Was this translation helpful? Give feedback.
All reactions