Re: CPU performance rises when I'm opening an other application/dialog
- From: "Robert Dunlop [MS MVP]" <rdunlop@xxxxxxxx>
- Date: Tue, 17 May 2005 04:47:58 -0700
"Zman" <zman@xxxxxxxxxxxxxx> wrote in message
news:eAIUWMoWFHA.2572@xxxxxxxxxxxxxxxxxxxxxxx
> The way the sample framework does it has changed several times and is
> about to change again for June according to Tom's blog. The move away from
> DoEvents was becuase of the large amounts of allocation and deallocation
> that are caused when you call that method multiple times per second.
Ah, that would make sense.
I see a lot of people having issues with per-frame allocations, particularly
when they involve classes that contain unmanaged resources that the GC
cannot factor into its collection algorithm. Part of the problem may be a
matter of not thinking through what allocations are implied, for example
making a call like this every frame:
dev.SetTexture(0,Texture.FromBitmap(...));
In unmanaged code it would be more obvious what costs you are incurring, for
example the above would look something like:
IDIRECT3DTEXTURE9 *pTexture;
CreateTexture(....,&pTexture);
//...code to load bitmap to newly created texture
....
pDev->SetTexture(0,pTexture);
pTexture->Release();
Per-frame allocations need to be avoided in managed code, maybe more so than
in unmanaged code. A better implementation of the above example would be to
create the texture once and re-use it each frame. Not only will that
prevent repeated allocations and the need to de-allocate them during garbage
collection, it also means that the texture will be graduated to an older
generation by GC and will not have to be scanned during a partial garbage
collection pass.
> For those of you who don't subscribe to my RSS feed I wrote up all of the
> discussions here http://www.thezbuffer.com/articles/185.aspx
Great info, thanks! I'll have to read my way through that when I get a
spare moment.
--
Robert Dunlop
The X-Zone
http://www.directxzone.com/
Microsoft DirectX MVP
-------------
The opinions expressed in this message are my own personal views and do not
reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation
with Microsoft.
.
- References:
- CPU performance rises when I'm opening an other application/dialog
- From: Wilfried Hafner
- RE: CPU performance rises when I'm opening an other application/dialog
- From: Michael Schwab
- Re: CPU performance rises when I'm opening an other application/dialog
- From: Robert Dunlop [MS MVP]
- Re: CPU performance rises when I'm opening an other application/dialog
- From: Robert Dunlop [MS MVP]
- Re: CPU performance rises when I'm opening an other application/dialog
- From: Zman
- CPU performance rises when I'm opening an other application/dialog
- Prev by Date: RE: CPU performance rises when I'm opening an other application/dialog
- Next by Date: Re: Sprite.Draw draws differently on different computers
- Previous by thread: Re: CPU performance rises when I'm opening an other application/dialog
- Next by thread: RE: CPU performance rises when I'm opening an other application/dialog
- Index(es):