Re: Custom keywords and compiler-supplied code

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi - thanks for the responses.

Just a few final thoughts...

1. Having to sprinkle GUI code with InvokeRequired tests means the GUI
looses focus. Also, a third-party control may not have thread-awareness
built into its event handlers. Therefore if you wired a threaded event
to it you'd have a problem. Making the threaded code have optional
synchronisation on its event-firing is one good way to alleviate this.

2. By not having the ability to have customised compiler-generated code
all of the fully generic solutions require the use of
ISynchronizeInvoke.Invoke or Delegate.DynamicInvoke, etc. These are all
late-bound calls and are significantly slower than calling a delegate
directly. I.e. the C# compiler and JIT compiler between them have
features that cannot be exploited by an end-programmer. I 100% agree
that keyword bloat is bad - I'm not asking for that. What I want is
some way to emulate the compiler's ability to inject code and have
intellisense pick it up.

3. Because C# generics are supported by the run-time (whereas C++
templates are processed at compile-time), it is not possible to exploit
them fully to solve this problem. I.e. a generic method cannot get
access to a compiler-supplied Invoke method on a delegate, only the
DynamicInvoke method which of course is late-bound and slow.

4. Regarding the runtime handling of a delegate's Invoke method, I was
referring to the following IL example:

..method public hidebysig newslot virtual
instance int32 Invoke(int32 a,
int32 b) runtime managed
{
} // end of method MyDelegate::Invoke

[This is generated from "public delegate int MyDelegate(int a, int
b);"]

I was wondering what the JIT compiler does with this - out of
curiousity :)

As a very final comment, here is a sample of code (from my threading
class) I'm now using in my test application. This allows the event to
be used directly if a synchronous call can be made, otherwise an
asynchronous call is made.

Note: evOnTick is an event, eventSync is of type ISynchronizeInvoke.

if (evOnTick != null)
{
if ((eventSync == null) ||
(eventSync.InvokeRequired == false))
{
// fast and direct call to the handler[s]
evOnTick(this, eventArgs);
}
else
{
// asychronous call, slow but safe!
eventSync.BeginInvoke(evOnTick, new object[] {
this, eventArgs });
}
}

Thanks again for feedback,
Jon.

.



Relevant Pages

  • Re: Mulitihreading problem with BackgroundWorker
    ... In the examples I have seen, all of the code is contained within the DoWork ... and ReportProgress is called from within DoWork. ... // I have tried the Invoke method on the label, but now the compiler doesn't ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: large files: when ubiquitous?
    ... >> The fact that undefined behaviour is invoked is an immediate consequence ... If your program complies with the rules of the C standard, ... branches are completely equivalent and both invoke undefined behaviour ... As with every transformation a compiler does, ...
    (comp.os.linux.development.system)
  • Re: Java VM Address Space
    ... By everyone else's definition of the word "compile" Java bytecode is ... A second stage of the compiler ... which mostly resemble the set written in the Java language. ... the four invoke opcodes could be said to ...
    (comp.lang.java.programmer)
  • Re: sizeof operator implementation
    ... sizeofat compile time. ... How does C compiler gets value at ... it definitely invokes UB due to casting 10 to a pointer type; might as well cast 0 and make what you're doing obvious. ... Casting 10 to a pointer type does *not* invoke UB, ...
    (comp.lang.c)
  • Re: The C Programming Language: Third Edition
    ... the compiler in C90 conforming mode for portability reasons. ... Frankly thats a silly point to raise when claiming the compiler ... You could as well say it doesn't support ... Of /course/ it doesn't, if you don't invoke ...
    (comp.lang.c)