Garbage collection and soft real-time apps

G

Guest

Before I get into the question -- I know .NET isn't the right solution for
this app but it's part of my clients requirements and writing this in C++
isn't an option. That being said -- my app is a stock ticker using the
managed DirectX libraries and the animation needs to be perfectly smooth.
Problem is that the garbage collector will kick in from time to time and
cause my render thread to miss a frame and makes it look like hell (even at
75 hz it's quite noticeable).

Is there any way to prevent managed code to not block on garbage collection?
I know this generally isn't a good idea but all my render thread is doing is
calling Device.Present -- all the other threads aren't critical and can be
suspended. Any ideas would be greatly appreciated.
 
D

David Browne

Oculus said:
Before I get into the question -- I know .NET isn't the right solution for
this app but it's part of my clients requirements and writing this in C++
isn't an option. That being said -- my app is a stock ticker using the
managed DirectX libraries and the animation needs to be perfectly smooth.
Problem is that the garbage collector will kick in from time to time and
cause my render thread to miss a frame and makes it look like hell (even
at
75 hz it's quite noticeable).

Is there any way to prevent managed code to not block on garbage
collection?
I know this generally isn't a good idea but all my render thread is doing
is
calling Device.Present -- all the other threads aren't critical and can be
suspended. Any ideas would be greatly appreciated.

I think the best you can do is minimize the impact of garbage collection
using a two-pronged approach.

First thing is to work hard to produce less garbage. The less garbage you
produce, the cheaper and less frequent collections are. Using structs,
pooling objects, minimizing string allocations, and reusing buffers can
dramatically reduce the amount of garbage generated by your application.

Second is be to collect on your own schedule. When you know there is
garbage and you have some time, force a collection. In a winforms app where
your appliction owns the whole process and all of the memory allocations,
you can figure out when and where to collect better than the garbage
collector. For a general purpose application it's not worth the trouble,
but when you can't afford those little pauses it can be.

David
 
G

Guest

Thanks,

We've actually done both of those things and really pared down our throwaway
objects. Still, a generation 0 garbage collection can take over 15ms which
is about all the time I have to swap backbuffers (we're pre-rendering
backbuffers to help alleviate the problem).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top