Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
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. –  Ricket Aug 30 '10 at 2:37
I'm on stackoverflow also, but I'm still learning the mix of what questions are valid for here. –  Hitesh Aug 30 '10 at 2:55
This question seems perfectly fine here. After all, he probably got the abswer he needed. See this: meta.gamedev.stackexchange.com/questions/3/… –  Tetrad Aug 30 '10 at 4:01
add comment

1 Answer 1

up vote 12 down vote accepted

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.

share|improve this answer
Some great resources. I should get a chance to try it out in a couple days. –  Hitesh Aug 30 '10 at 2:51
+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. –  Kornel Kisielewicz Aug 30 '10 at 10:27
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. –  Ricket Aug 30 '10 at 16:02
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. –  ZorbaTHut Aug 30 '10 at 20:12
The trouble with this sort of reasoning is that it tends to only be valid on windows. Some systems have hard memory constraints. Also, if you care about perf, you probably don't want the memory "automatically" swapped for you when you start using too much. –  BigSandwich Sep 21 '10 at 6:50
show 2 more comments

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.