0

I wrote a C++ program that lists all top-level windows and gives user an ability to live capture any of them using GDI.

Basically, there runs a Windows timer with 0 delay pointed (of course, there no zero delay) - it gets specified window's DC, blits it to compatible GDI HBITMAP, GetDIBits of that bitmap to char array and finally creates ID2D1Bitmap from that char byte data, that is being rendered via Direct2D. And all of that many times per second, so I can get about 60fps cast from window.

All data is being free, and the task manager says, that the memory of the process is not raising, but the page fault value, exactly after I choose window to start being captured is growing up.

After about 10 minutes there are almost 100 millions page faults, as task manager displays. It grows up with about 100k units per step, despite, as I already wrote memory is not raising, so, I assume there is no memory leak.

The process with the nearest page fault count value - msedge.exe has only 5 millions page faults, running for about ten hours. It raising for Edge also, but not so fast as in my program.

I read that big page fault value can reduce the performance, but currently it seems to be ok.

So is it ok? Should I do something?

Ngdgvcb
  • 155
  • 6
  • At a glance you need to stop calling so many functions repeatedly. Call it once and store it in a variable. – Blindy Aug 26 '22 at 14:25
  • @Blindy, but I need to. I want to capture windows at 60fps at least – Ngdgvcb Aug 26 '22 at 14:26
  • 3
    Page faults are a perfectly normal part of running a program. The OS reacts to them by mapping real memory or paging in stuff from secondary storage. Unless you are experiencing an *actual* performance problem, I wouldn't worry about them. They are *usually* an implementation detail you don't need to care about as an application developer. – Jesper Juhl Aug 26 '22 at 14:27
  • @JesperJuhl, well, "normal" is something that others mostly have. As I wrote - process with nearest page faults count value has only 5 millions page faults and it raising not so fast as in my program – Ngdgvcb Aug 26 '22 at 14:28
  • @JesperJuhl *They are usually an implementation detail you don't need to care about as an application developer*, why then task manager gives me opportunity to explore it? – Ngdgvcb Aug 26 '22 at 14:31
  • [Why should I not upload images of code/data/errors when asking a question?](https://meta.stackoverflow.com/q/285551/995714) – phuclv Aug 26 '22 at 14:31
  • @Ngdgvcb So what? So, what you do in your code is causing more pagefaults than what other programs on your machine do. Why is that a problem? Are you experiencing bad performance? If not, why do you care? You seem to think that pagefaults are a "problem" - they are not (usually) they are just a part of how your OS and CPU manage memory. – Jesper Juhl Aug 26 '22 at 14:32
  • @phuclv it was just an example of how my program works, not specifically code screenshot. I get it out, however – Ngdgvcb Aug 26 '22 at 14:33
  • For a driver developer to be useful info (actually, for an OS developer). For a user mode app development, page fault errors are not needed to be examined. – Michael Chourdakis Aug 26 '22 at 14:34
  • Without any code to go on it's impossible for us to tell however there are [newer ways of doing screen capture on windows](https://blogs.windows.com/windowsdeveloper/2019/09/16/new-ways-to-do-screen-capture/) – Mgetz Aug 26 '22 at 14:35
  • @Ngdgvcb "why then task manager gives me opportunity to explore it?" - Task manager gives you lots of info you don't usually need to care about. It's there for the rare cases when you *do* need to care. Just like `perf` on Linux can give you all sorts of details like "L2 cache misses" and whatnot - it's useful when you *need* it, but usually you don't and can just ignore it unless you have *an actual problem*. – Jesper Juhl Aug 26 '22 at 14:36
  • @MichaelChourdakis Disagree, excessive page faults can indicate bad memory access patterns in a user mode app. That can be a huge performance hit. The better question is "what is excessive?" – Mgetz Aug 26 '22 at 14:36
  • @JesperJuhl, *Are you experiencing bad performance?* - currently no, I launched the program and check it. It has 150 millions page faults already, by the way. Can it take storage? – Ngdgvcb Aug 26 '22 at 14:36
  • @Ngdgvcb Do you know what a page fault actually *is*? – Jesper Juhl Aug 26 '22 at 14:37
  • @Ngdgvcb the samples are C# but you can use the c++/winrt projections to do the same thing and it should be fine. – Mgetz Aug 26 '22 at 14:39
  • @Mgetz, oh WinRT, I didn't catch that. No, I need Window 7 support – Ngdgvcb Aug 26 '22 at 14:40
  • @JesperJuhl, not quite, thats why I was asking – Ngdgvcb Aug 26 '22 at 14:40
  • @Ngdgvcb are your clients paying for support of an unsupported OS? or is this for legacy content? Because otherwise I'd move away from win7 support if possible. – Mgetz Aug 26 '22 at 14:44
  • @Mgetz, well I currently on development state, not being thinking about clients too much, but Windows 7 support, I think just a must-have. If not Direct2D I'd also include XP support – Ngdgvcb Aug 26 '22 at 14:51
  • @Mgetz, if You interested, check the video I pinned, I found about week ago - it am going to use this method in nearest future. There also are sources, see on the channel https://www.youtube.com/watch?v=hRTgFTMnT_U – Ngdgvcb Aug 26 '22 at 14:53
  • @Ngdgvcb In short, a page fault is just a signal from the processor to the OS that "this page you are trying to access via this virtual memory address is not currently backed by a physical memory page". That is either completely harmless (and expected) if the OS has just given you a memory allocation that it has not yet actually backed by physical memory (which is sensible; you might not actually use it), or it's a problem because you tried to access memory you had not allocated (in which case the OS will kill your process with a SIGSEGV or similar). There's more to it, but that's the basics. – Jesper Juhl Aug 26 '22 at 15:07
  • @Ngdgvcb if you don't have clients demanding it I'd avoid supporting unsupported OSes. It's a lot of work and you can't ask MS for help if something is fundamentally broken – Mgetz Aug 26 '22 at 15:07
  • @Mgetz, what do You mean by "ask MS for help"?) – Ngdgvcb Aug 26 '22 at 15:41
  • @Ngdgvcb for a supported product you can log bugs on various things. For example I have several bugs open against MSVC's modules implementation. However if I were to open a bug against Windows 7 MS is going to ask me to cough up a lot of money for them to care because it's officially out of support. – Mgetz Aug 26 '22 at 15:51
  • [ShareX](https://github.com/ShareX/ShareX) for Windows is a screen capture & record program. Maybe their open source project has some useful insights for your project. – Eljay Aug 26 '22 at 17:09

0 Answers0