Problem with PagedMemorySize64

Started by
16 comments, last by jpetrie 6 years, 9 months ago

I'm using C#, and trying to figure out how much memory a process is using within the paging file or how much of its memory within physical RAM can be moved to the paging file if necessary.

 

Unless I'm mistaken (and I might be), the function PagedMemorySize64 is supposed to tell me how much is currently in the paging file, and PagedSystemMemorySize64 should tell me how much is in RAM but could be moved into the paging file at any time.

 

If those assumptions are correct, then so far so good.

 

However, even when "No paging file" is checked within my Virtual Memory properties window, these two functions both return positive numbers!  Why would that be?

 

Also, I opened the "Performance" tab on the Windows Task Manager, and in the section called "Kernel Memory (MB)" it says that "Paged" is a positive number (a pretty small number like in the hundreds, but I don't know if it's counting pages or bytes or what).

 

Am I imagining things, or is my computer actually using a paging file even when I tell it not to, or alternatively, do those paged memory size 64 functions not work or just not do what I think they do?

Advertisement

Not a Beginners topic. Also, not relevant to games. Do you have an explanation for why you're asking this on Gamedev.net?

OK then I guess like the other one, it should go in the General Programming forum.  That's "General" enough for it, right?  And how do you know it's not relevant for games anyway?  People save games in files all the time.  I'm really not trying to be snide, but just making a point.

Here's the situation: not everything on these forums has to be 100% about game development, but it should at least be potentially relevant. Maybe because you're using it in a game context, or someone else would. Maybe because it uses techniques or technology used in game development. Or maybe the answer might tell us something about how to better make games or how to improve our programming.

Your last few threads have only had the most tenuous link to games development, made worse by your refusal to explain what you are doing or why you are doing it. "I'm having trouble with file code that I can't show you, in an app I won't tell you about, while doing weird things with virtual memory, but since games also use files it's relevant" is not a compelling response.

And it's not a one-off - it seems to be the case for all your threads these days. If you just want to continue asking off-topic questions, Stack Overflow is probably the best place for you. But if you'd prefer to keep posting here, show us how this is on-topic.

OK sorry, but you don't have to close my threads like you just did with the other one.  I mean if you don't want to answer my question that's your business, but when you close it you prevent anyone else from possibly being able to answer it, even if they would have!

Oh, and also, if the "General Programming" must be about games then why is it called "General Programming"?

As a moderator it's part of my job to keep these forums clear of irrelevant clutter. Keep your threads relevant and they won't be closed.

For the answer to your last question, please consult the first paragraph of my last response.

Trying to address the original question ...

You need to do some reading to gain a much deeper understanding of how virtual memory works.  The last several questions on the topic show you have done almost no research, instead you just reach for likely-sounding names in the API and assume they do what you think they do rather than what they actually do.

PagedMemorySize64() documentation says it gives the value "Page File Bytes". That is private committed memory, which (if you have done your research you would know) is pageable memory your process owns and that you have written on. That is different from pageable memory your process owns but has not been committed.  None, some, or all of it may be located in a paging file. 

The system memory call is similar.

Okay so just to actually answer this even if its not game related (will agree its more akin to something that should be on stack overflow) - but may as well get an answer.

Your assumptions on how they work are for the most part correct, however the PagedMemorySize64 will return a value even if page file size is set to 0 or its not using a page file - as stated by Microsoft on their docs "The property value is equivalent to the Page File Bytes performance counter for the process."

Which if you read into will show you that it returns the amount of virtual memory being used for paging files HOWEVER if there is no paging file it will show the amount of virtual memory that the process has reserved in physical memory.

So even with paging files set to 0 on usage, it will still return a value.


There, question answered so you dont have to re-post to stack overflow - #LockThreadKylo

But seriously, threads should be game related and I feel bad for answering this :( 

Well thanks then GibbonThatCodes.  At least that tells me that I must be using the wrong function for what I'm trying to do, but I guess I'll still have to post to Stack Overflow or something to figure out which function I should use.

An alternative is to go read the documentation of the C# library. No doubt it's a lot, so you won't know it all in one hour or even one evening, but the global picture of the kind of things that exist there will stick.

If you do that a few times, you start to know where to look more precisely. In a few months, you know all the relevant major things from that library without ever needing to ask or search.

While I agree that it is not the fastest way at first, assuming you will be programming for many many years, I do think your investment will pay for itself several times during your career, at least it did for me in several languages.

This topic is closed to new replies.

Advertisement