Re: What is 'managed code'?



Very simply, managed code is code that the runtime system handles all
aspects of memory and resource management. The managed code model is that
of infinite resources. But since we know that resources on any given system
are finite, the runtime must do a lot of work to present this model. To do
this requires that the runtime system present a garbage collector that can
sweep through the application memory and find all unreferenced resources, be
they memory, IO Ports, files, etc., and properly close and release them back
to the OS. In the case of memory, the garbage collector must also compact
available memory to consolidate free space for further allocations.

VB 5&6 almost do this for memory only, and then only if you don't use direct
Windows API calls. When using ActiveX components, which are all COM
Objects, the Component Object Module runtime DLLs perform a simple reference
counting. When an ActiveX component's references go to zero, the COM
runtime releases the memory of the COM Object. Note that the COM runtimes
don't close files or other resources - they belong to the process and the OS
will close them when the process exits. In VB 5&6, memory references are
also reference counted, which means that it is possible to create two
objects that reference each other, yet are impossible to reference from the
application. The VB 5&6 Garbage Collector will never free these objects.
Nor can the VB 5&6 Garbage Collector consolidate free memory space. Neither
of these weaknesses of a reference counted memory scheme are usually a
problem.

Now to the kicker - VB 5&6 are a very sophisticated implementation of a COM
object, to the extent that each form is a COM Object. This is why you need
to be careful when referencing controls on a form during your Form_Unload
event procedures. Doing so creates a new reference to the form, which
prevents the form from being reclaimed by the COM runtime.

The major weakness of fully managed code is that it is significantly slower
than unmanaged code. The TAPI API is a near real-time API. Real-time and
Managed cannot be used in the same sentence. Other common Windows APIs that
fall into this category include the Multimedia API and DirectX. VB 5&6 are
partially managed and as such, tend to lie between fully managed code and
unmanaged code in performance. Runtime resource management of any type
incurs a performance penalty, regardless of language.

To those of you who think this is a .NET question - it's not. This is a
question of language design and implementation. In the Microsoft world,
..NET is fully managed, FoxPro and VB 5&6 are partially managed, and C/C++
(including the ATL and MFC extensions) is unmanaged. JAVA, APL, Smalltalk,
and Lisp are also fully managed. You can tell unmanaged languages by the
presence of explicit pointers to memory. Managed code generally doesn't
support explicit pointers except where required for call backs and event
handlers.

Mike Ober.


"Jack" <replyto@newsgroup> wrote in message
news:uLY4xBEsFHA.3720@xxxxxxxxxxxxxxxxxxxxxxx
> From MSN:
> This article discusses why Telephony Application Programming Interface
> (TAPI) is not supported from managed code.
>
> What is that managed code?
>
>


.



Relevant Pages

  • Re: What is managed code?
    ... managed code is code that the runtime system handles all ... > aspects of memory and resource management. ... But since we know that resources on any given ... > also reference counted, which means that it is possible to create two ...
    (microsoft.public.vb.general.discussion)
  • Re: dataset Performence Issue
    ... Microsoft that a DataSet is okay to abuse as a DataBase. ... Managed Code can never be as fast and as optimized ... very good for 90% of the situations i.e. normal memory usage, ... Merge/GetChanges - and oh lets not forget keeping your disconnected cache ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: dataset Performence Issue
    ... of data to hold in memory in some applications. ... Network and disk costs see to that. ... First of all, Dataset is guess what - Managed Code, and to send all the ... You need paging mechanisms etc. which are ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: using gzlib from c#
    ... I don't have a favourite memory leak finder, I'm afraid - but the main ... the kind of mistakes which can occur in interop may well ... >> The demand for the UnmanagedCode permission will still occur at link ... > piece of memory is being allocated by managed code, ...
    (microsoft.public.vc.language)
  • Re: using gzlib from c#
    ... I don't have a favourite memory leak finder, I'm afraid - but the main ... the kind of mistakes which can occur in interop may well ... >> The demand for the UnmanagedCode permission will still occur at link ... > piece of memory is being allocated by managed code, ...
    (microsoft.public.dotnet.languages.csharp)