Garbage Collection

B

Bob lazarchik

Hello:

We are considering developing a time critical system in C#. Our tool used in
Semiconductor production and we need to be able to take meaurements at
precise 10.0 ms intervals( 1000 measurement exactly 10 ms apart. In the
future this may decrease to 5ms ). I am concerned that if garbage
collection invokes during this time it may interfere with our measurement
results. I have looked over the garbage collection mechanism and see no way
to control when garbage collection occurs. Is there a way to pause and
start garbage collection? or some other technique that I can use to prevent
garbage collection while I am taking measurements?

Thanks

Bob
 
J

Jan Tielens

I don't know how you can prevent the GC, but you can force the GC to
collect:
System.GC.Collect()

How are you measuring time spans?
 
E

Eric Gunnerson [MS]

Bob,

It depends on what you mean by "precise". Windows in general doesn't make
timing guarantees, nor does the runtime, so I don't think you can do this
easily with a purely PC-based solution. Or, in other words, you can't do
"hard" real-time on Windows (and even soft real-time may take some work).
You might be able to get it to work (or make it close enough for your
application), but there are no guarantees on it continuing to work.

Can you do the sampling with hardware and then send it to a PC (or handheld)
over a serial link? That would give you buffering and make sure that you had
the samples at the right points.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://weblogs.asp.net/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Nick Malik

I may not be popular for suggesting this, but I'd recommend that you write
your measurement collection functions in unmanaged C++, and pass them into
the C# application for the rest of the work. You will get much better
control over timing.

If you are going to collect 1000 or 2000 measurements, and then stop
collecting, and then process data, you may be fine simply invoking garbage
collection at "safe" times (like before your data collection begins or after
it ends). On the other hand, if you collect your data using C# code, you
may have to have a way to prove that your measurements actually occurred at
10ms intervals, given that GC can occur at any time, and a plan for
collecting data again in the event that the first "measurement window" was
messed up by GC. IMHO, you are better off using unmanaged code for
fine-tune real-time measurements.

HTH,
--- Nick
 
J

Julian Nicholls

In addition to caveats from other posters.

Bear in mind that Windows is not a hard real-time operating system. You may
be hard pressed to do 1000 measurements at exact 100ms intervals, let alone
10ms or worse still 5ms, even in a device driver written in assembler. The
basic time tick in Windows is 10ms or 15ms, so doing anything at intervals
shorter than that is almost doomed to failure, especially in a managed
language.

I think garbage collection will be the least of your worries.

Best Regards
Julian Nicholls
 

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