Re: Thx and more details

From: Brian Tyler (brianmtyler_at_yahoo.com)
Date: 01/25/05


Date: Tue, 25 Jan 2005 09:21:15 -0600

Definately sounds like you want to go with a proxy then. How to handle it
now depends on your situation.

* If you want to modify the source code to change new calls into a proxy
call, look at the CodeDom API in the framework

* If you want to modify the binaries (assemblies) look at some open source
packages such as RAIL (http://rail.dei.uc.pt/index.htm) or using the .NET
reflection API directly.

* If you have digitially signed assemblies and thus can't write modified
versions back to disk, you need to use the the CLR profiling API. Definately
the most work of the three.

Anyone else have some ideas on approaches?

Brian

"Z. Cristi" <Z. Cristi@discussions.microsoft.com> wrote in message
news:A6A25D27-B8A3-4949-B491-4962889982AE@microsoft.com...
>
> Thank you all of you for the information provided. I am new to .NET, so I
> have to
> investigate if my problem fits one of your solutions. However, as Brian
> sugested, I
> provide here more detail:
>
> What I need is to have a user defined function called when the memory
> allocation
> fails. The normal behavior specified by the new operator should be
> guaranteed - it
> will throw an OutOfMemoryException exception - but the exception will not
be
> thrown by this function. This function should not return any value.
>
> I prefer this function to be written in the programers language, that is
C#.
> It doesn't mind me very much if I have to write some C/C++ code wrapping
C#
> code.
>
> Thx again.
> Z. Cristi
>
> "Brian Tyler" wrote:
>
> > No - you can't do this because allocation is done by the GC out of it's
> > heaps. If you can tell us what you plan to accomplish by this we might
be
> > able to point out some alternatives. For example, three come to mind...
> >
> > 1. You can take control over the allocation of heaps for the GC if there
was
> > some reason you needed to (see the CLR hosting interfaces for 2.0).
> >
> > 2. Depending on what you are trying for you can also take a look at the
CLR
> > Profiling interface (no, not the CLR Profiler - the app built on the
> > profiling API). It has a callback when memory is allocated (see
> > ObjectAllocated()). However, you must write this code in unmanaged C/C++
so
> > it can be a bit limiting.
> >
> > 3. Another approach you could use is the profiling API to hook the JIT
> > callbacks and swap out the newobj instructions with calls to your own
proxy.
> > I've written code like this and there are some examples in some MSDN
> > articles.
> >
> > "Jon Shemitz" <jon@midnightbeach.com> wrote in message
> > news:41F52D97.4773AF0F@midnightbeach.com...
> > > Z. Cristi wrote:
> > >
> > > > When I say that I want to have a custom allocation routine, I
mean
> > > > that I want to use the new operator provided by the C# language,
but
> > > > the this new operator must call a custom routine.
> > >
> > > I don't believe that there is any way to do this, though I may be
> > > wrong.
> > >
> > > If you want some non-default behavior, like not setting every byte of
> > > the new object to 0, you're probably out of luck. The dox are pretty
> > > clear that the CIL "newobj instruction allocates a new instance of the
> > > class associated with ctor and initializes all the fields in the new
> > > instance to 0 (of the proper type) or null references as appropriate.
> > > It then calls the constructor ctor with the given arguments along with
> > > the newly created instance." That says to me that zalloc is enforced
> > > by the jitter, and you only get control after the fill.
> > >
> > > If you just want some sort of registration routine called, you'll just
> > > have to declare a very basic type that your classes inherit from. Yes,
> > > this will not allow you to register instances of FCL or third-party
> > > classes.
> > >
> > > --
> > >
> > > www.midnightbeach.com
> >
> >
> >



Relevant Pages

  • Re: Howto extract proxy from .pac script?
    ... This .pac file allows selecting the appropriate proxy ... You need a full blown JavaScript interpreter - .pac files can use any ... What I was looking for is a dedicated API in Mac OS X ...
    (comp.sys.mac.programmer.help)
  • Re: com_ptr<T>
    ... I totally forgot about this fact when I was editing this for the OP. ... template was special case for objects produced by a proxy gc. ... The proxy gc is a C API, ... template wrapping a not so C++ friendly C API. ...
    (comp.lang.cpp)
  • Re: How to return a user-defined data type object from a webservice?
    ... I recommend naming web references with the word "Proxy" in the name, ... Also, Brad, if you're going to suggest that people modify the proxy class, ... John Saunders | MVP - Windows Server System - Connected System Developer ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Calling a method on a webservice
    ... implementations. ... You need to modify the generated client proxy class and replace the ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Calling a method on a webservice
    ... implementations. ... You need to modify the generated client proxy class and replace the ...
    (microsoft.public.dotnet.framework.webservices)