Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why does my workingsetsize always equal 0?

2 views
Skip to first unread message

Kun Niu

unread,
Apr 30, 2008, 8:58:00 AM4/30/08
to
Dear all,
I'm trying to use GetProcessMemoryInfo to get the workingsetsize of my
process.
The function is called in my own process, so I think that I've got all the
privileges.
The program is written with multithread.
And I create a timer to periodically get workingsetsize of my process.
But to my surprise, no matter I put the PROCESS_MEMORY_COUNTERS variable
locally in the function or I set the PROCESS_MEMORY_COUNTERS variable as
global, I alway get 0 after I call GetProcessMemoryInfo in the timer callback
function.
Then I try to get the value in a separate thread.
But I get the same result.
Workingsetsize always equals to 0.
So will anyone please help me so that I can implement the functionality like
windows task manager with a process memory usage shown to me?
Thanks for any advice in advance.

David Lowndes

unread,
Apr 30, 2008, 1:55:43 PM4/30/08
to
>I'm trying to use GetProcessMemoryInfo to get the workingsetsize of my
>process.
>The function is called in my own process, so I think that I've got all the
>privileges.
>The program is written with multithread.
>And I create a timer to periodically get workingsetsize of my process.
>But to my surprise, no matter I put the PROCESS_MEMORY_COUNTERS variable
>locally in the function or I set the PROCESS_MEMORY_COUNTERS variable as
>global, I alway get 0 after I call GetProcessMemoryInfo in the timer callback
>function.

Is the timer or separate thread significant - what do you get if you
call it from your main thread?

The following snippet works for me in a console application:

PROCESS_MEMORY_COUNTERS mc;

if ( GetProcessMemoryInfo( GetCurrentProcess(), &mc, sizeof(
mc ) ) != 0 )
{
printf( "%WorkingSetSize: %d\n", mc.WorkingSetSize );
}

Dave

Kun Niu

unread,
May 1, 2008, 8:58:01 AM5/1/08
to

"David Lowndes" wrote:

Thank you for your reply.
It's true that I try to call the function in my main function.
It returns the write number.
But after that, my program aborted abnormally.
So, I'll have to try to get the value in another thread or in a timer
callback function.
Thanks again for your attention and reply.

David Lowndes

unread,
May 1, 2008, 9:05:29 AM5/1/08
to
>It's true that I try to call the function in my main function.
>It returns the write number.
>But after that, my program aborted abnormally.

Why?

Dave

Kun Niu

unread,
May 1, 2008, 10:21:01 AM5/1/08
to

"David Lowndes" wrote:

Thanks again for your attention and fast reply.
This is also what I'm after.
No error box arises before my program terminates.
Now I have to write another program and record the workingsetsize.
Just wonder why the program can't get its own workingsetsize correctly.
Or do I have any other way to work around this?
Get the same result with another API.
Thanks for any attention and reply in advance.

David Lowndes

unread,
May 1, 2008, 10:52:18 AM5/1/08
to
>No error box arises before my program terminates.
>Now I have to write another program and record the workingsetsize.
>Just wonder why the program can't get its own workingsetsize correctly.

If I were you I'd first check that the relevant piece of code to get
the value works in a simple example project. Once you've done that you
need to pinpoint the cause of the apparently catastrophic problem in
your real application - I can't see any reason why your application
shouldn't be able to get the value successfully.

Dave

Ben Voigt [C++ MVP]

unread,
May 1, 2008, 2:21:13 PM5/1/08
to
Kun Niu wrote:
> "David Lowndes" wrote:
>
>>> It's true that I try to call the function in my main function.
>>> It returns the write number.
>>> But after that, my program aborted abnormally.
>>
>> Why?
>>
>> Dave
>>
>
> Thanks again for your attention and fast reply.
> This is also what I'm after.
> No error box arises before my program terminates.

Sounds like either stack overflow or intentional shutdown.

0 new messages