Win32 - Memory Allocation

Allocating memory really dynamicaly is not exactly the best to do. Better is to allocate a huge block of memory, and inplement your own allocating inside it. You won’t get memory fragmentation this way for example. This of course only applies to often used and big blocks of geometry, like model data or something like this. Also, your program can check for “memory violations” easily this way.

Of course you’ll get fragmentation, unless you only use it for one thing at a time. A good ground rule might be: If you have to start managing it yourself(writing a storage allocator etc.), let the OS do it for you.

Static memory allocation is limited in Windows. You generally use Win32 API functions to allocate a huge amount of memory(GlobalAlloc(), LocalAlloc(), Virtualalloc, etc.), though dynamic memory allocation with the ‘new’ operator works pretty fine, but I don’t know which method it uses.

Kistomika

I don’t agree completely with your opinion, though it is correct for many things.
If you do your own allocating in a huge block, allocating is way faster! You could start allocating from the back and from the front. Then just move the pointers and return them. For debugging reasons, you could spare some bytes inbetween (or even just a single, but for crashing reasons a few more might be good).
Also, try to avoid reallocation, it’s obvious why…

Don’t suppose you would like to help?

I would but I’m in my final year of an engineering degree and I don’t have the time. Sorry

Yeah, it’ll be faster to allocate big chunks, but then you get the extra cost of doing the management. My point was just that if you need to manage it yourself (in a non trivial way, it’s not that hard to allocate AGP mem and fill it up with vertices when you need to render something) you better make sure sure your storage allocator is better than the one in the OS. I think you’re more or less talking about memory pooling though, which is a good thing and easy to encapsulate.

Hi,
How does one tell how much of the graphics card memory they are using and does vertex data get stored there automatically?