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:
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:
HANDLE Job = CreateJobObject(NULL, NULL);
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_PROCESS_MEMORY;
info.ProcessMemoryLimit = mem * 1024;
SetInformationJobObject(Job, JobObjectExtendedLimitInformation, &info, sizeof(info));
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).
int maxmem = info.PeakProcessMemoryUsed / 1024; // I need this in KB
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.