Thank you, that did it.
Now, I've managed to come up with something. I assumed all the memory limits need to be set in bytes, is that correct?
Second, after I create my job object like this:
Code:
HANDLE Job = CreateJobObject(NULL, NULL);
JOBOBJECT_EXTENDED_LIMIT_INFORMATION info;
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_PROCESS_MEMORY;
info.ProcessMemoryLimit = mem * 1024;
SetInformationJobObject(Job, JobObjectExtendedLimitInformation, &info, sizeof(info));
And create a process in suspended mode, assign it to the job object then resume it and wait for it to end, I want to know the peak memory that it used. For this I do:
Code:
int maxmem = info.PeakProcessMemoryUsed / 1024; // I need this in KB
Now, this maxmem is different than what I get by using GetProcessMemoryInfo, and what I get by calculating the memory used by hand (I have the source to the program). Not to mention it's the same for multiple runs of the same process, even if I know for sure the used memory changes (increases) for each run (again, due to GetProcessMemoryInfo and hand calculations).
Also, I know the same way that the program can end up using up to 6 megs of memory. If I set mem to, say, 4 megs / 1024, the program does not end as it should due to insufficient memory.
So, I'm obviously doing something wrong, any suggestions? Maybe I should use WorkingSetSize instead? Is that reliable though, I read there are ways around it, or that it's just a suggestion to the OS, not a hard limit.