15
\$\begingroup\$

I want to programmatically determine at runtime how much video card memory is being used by my program. Specifically I'm wondering about how to do it on a Windows machine using OpenGL, but am interested of ways to do it on other platforms as well.

I know there are utilities out there that will show me the memory usage as my program is running, but I want to be able to query that information from my code.

\$\endgroup\$
3
  • \$\begingroup\$ P.S. I already answered your question, but this would've been better suited for stackoverflow.com since it's just a general programming question. If my answer isn't thorough enough you are welcome to repost it there and see what responses they give. \$\endgroup\$
    – Ricket
    Commented Aug 30, 2010 at 2:37
  • \$\begingroup\$ I'm on stackoverflow also, but I'm still learning the mix of what questions are valid for here. \$\endgroup\$
    – Hitesh
    Commented Aug 30, 2010 at 2:55
  • 3
    \$\begingroup\$ This question seems perfectly fine here. After all, he probably got the abswer he needed. See this: meta.gamedev.stackexchange.com/questions/3/… \$\endgroup\$
    – Tetrad
    Commented Aug 30, 2010 at 4:01

1 Answer 1

14
\$\begingroup\$

You can find the video memory of an Nvidia card using the NVX_gpu_memory_info extension, or an ATI card using ATI_meminfo. Here is a snippet of code I found which might get you started.


However, Paul Nettle at flipcode wonders why one would want to find the available video memory, saying:

The reason it's difficult (and sometimes impossible) to determine the amount of video memory is very similar to the reasons why OpenGL won't let you lock the frame buffer and access it directly.

And goes on to explain, in essence, that an "amount of video memory" might not actually mean anything. I concur with him on the reasoning that, for example, the amount of "free" memory in a Windows Vista/7 machine is irrelevant; hopefully there is no free memory, because free memory is wasted memory. But there is always some areas of memory dedicated to caches which are cleared by Windows, should an application need them.

\$\endgroup\$
7
  • \$\begingroup\$ Some great resources. I should get a chance to try it out in a couple days. \$\endgroup\$
    – Hitesh
    Commented Aug 30, 2010 at 2:51
  • \$\begingroup\$ +1, the snippets are great. However, I don't fully agree about not meaning anything -- it's always better to check the amount of memory than letting your program spectaculary fail. \$\endgroup\$ Commented Aug 30, 2010 at 10:27
  • \$\begingroup\$ Well, but I think the point was not necessarily that you shouldn't check the amount of memory, but that the amount of memory isn't a clear indicator of anything. When the card runs out of memory it might mean it will fail, or it might mean your texture data will just be automatically swapped in and out as necessary. 0 memory might not actually mean a fatal out-of-memory error. \$\endgroup\$
    – Ricket
    Commented Aug 30, 2010 at 16:02
  • 2
    \$\begingroup\$ Personally I'm planning to use this as a simple guideline for tracking leaks and watching my hardware compatibility. Using "20mb"? Yeah that'll probably run on anything on the market today. Using "500mb" on a simple game with half a dozen dynamically-allocated textures with a lot of churn? Whoops something has probably gone rather wrong with my garbage collection. \$\endgroup\$
    – ZorbaTHut
    Commented Aug 30, 2010 at 20:12
  • 1
    \$\begingroup\$ Unfortunately the GL spec says that when the driver returns GL_OUT_OF_MEMORY it's now in an indeterminate so once you get out of memory you're basically S.O.L. For game that's not so bad but for an app like say Photoshop that's unacceptable. \$\endgroup\$
    – gman
    Commented May 24, 2012 at 22:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .