• Civilization 7 has been announced. For more info please check the forum here .

Memory Leak?

Think about this, every tile has 256 vertices just for the base tile. Let's say you play on 100x100 map - that is 2,560,000 vertices. A vertex in Gamebryo is typically 3 floats, this means 12 bytes per vertex. So far, we are up to 30,720,000 bytes just for the base map. Now add about 100 vertices per tree (remember that a forest tile has about 20-30 trees), ~50 per basic building, mines have a couple of hundred each, oh yeah, roads have 4 vertices per bend. I'd guesstimate each unit as 500+ vertices. Leaderheads are into the thousands each (I think these aren't being freed when they are done talking at you - which could be an issue).

250MB doesn't sound unreasonable.
 
Agreed, which is why you need to build tight restrictions into the "render/no render" decision tree... Is it truly necessary to have that much geometry (i.e., the entire map and everything on it) in memory at once. It's just a question of at which level you put the master yes/no decision.

It will be very interesting to check the system load once the first patch is released.

I'm not banging on the developers here. Goodness knows I've written some code which looked like it was elegant, efficient and sublime... and then it ran like a total pig in practice, while some of the ugliest, brute-force stuff has ended up running like an S-O-B... We've all been there, and I trust that if there is a way to streamline processes, they'll take it...

They could do much worse than sending a letter of interest to Harkonnen though... He's done some pretty righteous debug work here; even if he has only reduced the possibilites of point-of-constriction, that's most of the battle... Occam's Razor, baby... :)
 
warpstorm
It does sound unreasonable because such things are normally reused. I.e. we should have one copy of heights for each terrain type and then just use world matrix to draw it in correct place and under correct angle. Same stands for units. Drawing 500 player models in any FPS isn't more memory consumptive as rendering only 2 or 5 of them. And each of these 500 instances can be freely rotated or translaeted in 3D space.

Same stands for textures. My first hypotesis was that they render earth surface into entire texture of a globe size (splitted into 512x512 chunks, but this way). After profiling it looks more like they did that to vertex data.

I heard from someone that recent version of Pirates has same engine and same problems. Is that true? Did they fix it? If this is true, then I doubt there will be a patch soon... Pirates are longer on the sale, and this problem with civ4 would either be already had been solved or it is not solvable at all if they couldn't fix it in Pirates by civ4 release date. But that makes my patch even more interesting... ;) Did anyone try Pirates? Were there such memory problems?
 
At least it is unreasonable for index buffers (which vertex belongs to which face), and that's what I've just found... Among 60Mb index buffer data 52Mb is a waste according to my hash function, i.e. a copy of some other index buffer coexisting at the same time. That is, I am about to save 50Mb with index buffers pretty soon.

If same trick will work for vertex buffers (probably after bringing to same origin/orientation), then my patch will finally see you CPUs...
 
Harkonnen said:
Same stands for units. Drawing 500 player models in any FPS isn't more memory consumptive as rendering only 2 or 5 of them. And each of these 500 instances can be freely rotated or translaeted in 3D space.

And for things like trees, units, etc, I'm sure they do. This was just me not thinking before typing since I've used Gamebryo instancing myself.
 
hi haronnon
some feedback i hope you can use.
after installing the earth/nasa mod i tried playing the game once more. :blush:
i DIDNOT have a system reboot (for the first time!!) but a CTD.:crazyeye:
perhaps the mod changed the textures for the better?
 
hi everyone,
I try pirates last years, and i think there's the same memory problems because i remember there is a lot of lag at the end of the game. it's look like the the civ 4 problems but the game stay playable. in this game the map is always the same and smaller than the huge map of civ4, this is probably why the game stay playable.
I'm going to re-test it without and with the patch and look at the amount of memory it take.

i hope you understand what i say because i know that my english need improvement... i'm french so don't blame me for my english
 
warpstorm said:
And for things like trees, units, etc, I'm sure they do. This was just me not thinking before typing since I've used Gamebryo instancing myself.

Well, I'm not sure with what I see... BTW, it lags even more on map regions with trees. I don't think this is Gamebryo issue. This looks like Firaxis issue on using their interfaces.

Well, here comes more investigation. As I said above, 55Mb of index buffer data can be shrunk to just 2-3Mb. I think most of these are square grids representing tiles while vertex coordinates represent heights.

Amongst 200Mb of vertex data only 45-50mb are dupes, others are unique even on coordinates (leaving textures aside), and even on slide/rotation invariants, I tested. So we can't save more then 50Mb here.

Earlier I tried to redirect textures (~45Mb overally) to D3DPOOL_DEFAULT, thus removing their D3DPOOL_MANAGED copy in main memory, this gave another 45mb. With 128mb of video memory, around 60Mb of vertex data can also be pushed there (given Geforce3 and higher TnL enabled video card, Geforce2 can't store vertex data in video memory, not sure about gf4 mx, though they are TnL-enabled).

So, overally this will reduce memory usage to 150-200Mb. With my system this will be 450-500Mb. It still will swap, but it will become much more playable. Even with simple pushing textures to video memory playability increase was visible.

Probably I will be able to fight off a little more with my memory manager which I wrote through that hard week when I started.

Profiling is done, now time to code last findings on D3D.

One more thing: the game creates geometry data for tiles on-the-fly when you first time scroll to them, and it loads some more if there is some free memory. So, 650Mb is bare minimum just to show my core cities. With 1Gb system it will load some more tiles around. With small map it creates geometry for all tiles, and never swaps again.

Memet
Thank you for the info. This gives me some relief that my work won't last for 1-2 weeks until Firaxis releases own patch which fixes these things from inside. BTW, your English is very good... according to my Russian :)
 
Harkonnen, can I ask a question?

With huge map (which I now try to play on all the time for the realism, i.e. your workers actually have something left to do after 1500 AD:) , Ive noted that the whole game is using a constant 1.2 GB of ram in later game stages(from task manager).

With your changes , approximately what amount does that come down to?

Ive 3.4 gz cpu, but (only)512mb DDR ram , and I could upgrade it to 1GB for £30, but as my system is only 2 months old , it would invalidate my guarantee....but if it makes Civ IV playable on late game with huge maps.........

p.s. your English seems fine too :)
 
Harkonnen said:
Well, I'm not sure with what I see... BTW, it lags even more on map regions with trees. I don't think this is Gamebryo issue. This looks like Firaxis issue on using their interfaces.

Well, I would have assumed that they instanced trees. The one thing to consider is that trees are animated, not static. It could be the animation that is killing frame rate.
 
DrewBledsoe
Hmm... Can you send me your 1.2Gb savegame to headden@karelia.ru please? Just my 512Mb system uses approx. 650-750Mb while 1Gb systems use 1.2Gb with the same map.

My hypotesis was that civ4 estimates something based on amoung of free RAM, but it looks like some other thing is affecting it... Probably CPU or video... What video do you have?

It can save same 150-200Mb improving playability, but not much, or it can save 600-800Mb (if savings will be proportional too) making it much more playable.
 
Pirates had no sort of problem like civ 4 does... one of the first things I did when I was getting constant CTD's with Civ4 was to try and play Pirates knowing they used the same graphics engine... I have no lag, no CTD's and no graphical errors with Pirates... then again it is 90% ocean and clouds though lol
 
@BlueBomberDude:
Unless I am missing a major point then the severe problem with increasing lag due to excessive memory (ab)use have nothing to do with any AI routine.
 
Erm, I'm a touch confused here, so please explain....

Why wouldn't a programme slow down in the case of a memory leak?

If the memory leak eventually uses up all the physical memory, then generally (on Windows at least) doesn't anything new that needs to be allocated to memory have to go into the swapfile / virtual memory, which is on the hard disk? Isn't the hard disk significantly slower to read from / write to than RAM?

Therefore wouldn't it make sense to conclude that if a memory leak uses up all the physical RAM, forcing the use of virtual memory, the game therefore has to load anything new into virtual memory, and thus has to slow down to HDD speeds...?

DaEezT said:
Just remember: memory leaks don't cause slowdowns and having more main memory doesn't really help either (at least on the average windows system).
 
/dev/null
I think Windows assigns swap file space to allocated memory pages once physical memory is no longer available. This allows to get page fault when it is accessed, so Windows can implement LRU (least recently used) mechanics to keep frequently accessed data in RAM. This means that leaking memory will eventually end its life in the swap file and will not affect performance once there since it will never be accessed.

Also, there are no memory leaks in this game. There are memory overuses, that's true. I've just eliminated 50Mb, and it has become playable with my 512Mb!! Yeah!

I still didn't implement two other things which will free 150Mb more. My patch is very soon.
 
Harkonnen said:
DrewBledsoe
Hmm... Can you send me your 1.2Gb savegame to headden@karelia.ru please? Just my 512Mb system uses approx. 650-750Mb while 1Gb systems use 1.2Gb with the same map.

My hypotesis was that civ4 estimates something based on amoung of free RAM, but it looks like some other thing is affecting it... Probably CPU or video... What video do you have?

It can save same 150-200Mb improving playability, but not much, or it can save 600-800Mb (if savings will be proportional too) making it much more playable.

No, the savefiles are only in the region of 650 -750 mb , as you stated, but the GAME is using 1.2 GB of total memory , so I assume (well it must come from somewhere) that the rest has to come from swap file...which of course means it runs very slowly. My vid card is pci 128 mb and cpu 3.4gz P4....I'm confused...
 
DrewBledsoe said:
No, the savefiles are only in the region of 650 -750 mb...
Surely you mean KB, I have yet to see a CIV save game (even from huge maps) pass the 1MB mark.
 
CyberChrist said:
Surely you mean KB, I have yet to see a CIV save game (even from huge maps) pass the 1MB mark.

Ah yes kb not mb ..thanks for pointing that out
 
Emerentius said:
hi haronnon
some feedback i hope you can use.
after installing the earth/nasa mod i tried playing the game once more. :blush:
i DIDNOT have a system reboot (for the first time!!) but a CTD.:crazyeye:
perhaps the mod changed the textures for the better?
Harkonnen, I too have loaded this mod pack - I am going to try to play again tonite - I have backed up my data so I can tolerate a potential BSOD. I too have read the reports by some that it does speed up play. Perhaps the way the original texture layers are programmed is where some of the the issue lies - I beleive I read the mod creator says the only thing different is the cloud layer...check out the discussion post below.

I'll let you know if it changes anything in the perfmon I'll run.

BTW, mod pacjk here
http://forums.civfanatics.com/showthread.php?t=140246
 
Top Bottom