Manged Code Issues??

A

al

Hi,

I'm very confused about the following:
Can someone please explain the difference between Type and Strong
Typed Data and if there is untyped data in the Managed Code, and how
this relates to earyl and latte bindings? Also, what is the
defference between close and dispose and how they relate to Finalize
argument?

MTIA,
Grawsha
 
R

Rob Teixeira [MVP]

al said:
Hi,

I'm very confused about the following:
Can someone please explain the difference between Type and Strong
Typed Data

Type = data type, whether it's a primative type, value type, structure, or
reference type (class).
The data isn't necessarily strongly typed. The code is strongly typed.
Strongly typed code avoids implicit data type conversion and requires type
definition for all variables/references.
and if there is untyped data in the Managed Code,

All data is typed, however if what you mean is a loose generic type (like
Variant from VB6) then you can use the "object" type.
Some .NET languages allow you to compile code that isn't strongly typed,
others don't.
and how
this relates to earyl and latte bindings?

Early binding occurs when the compiler knows the interface ahead of time.
Late binding occurs when the compiler has no idea about the interface ahead
of time.

If I write
Dim X As MyClass
X = New MyClass

then call a method using that reference, like
X.GetTotalRevenue(Months.January)

the compiler knows that the GetTotalRevenue method exists on the MyClass
interface, and can call the code directly. This is early binding. However,
if I write this instead:
Dim X As Object
X = New MyClass

then call the same method:
X.GetTotalRevenue(Months.January)
the compiler has no idea that the "object" instance will have a
GetTotalRevenue method when this code runs. It has to inspect the object and
make sure that the object supports the method AND supports a method that has
the right number and type of parameters provided (or can be converted to
such), then invokes the method by using reflection. This is late binding,
and it is significantly slower.
Also, what is the
defference between close and dispose and how they relate to Finalize
argument?

If it sounds like it makes sense to have a Close method on a class (like it
makes sense to close a Stream or a Connection), then you typically code a
Close method. It basically does the same thing as Dispose in most cases.
Finalize is called when the Garbage Collector is about to wipe out the
object data from memory. It is the last chance for the object to see if it
hasn't be properly disposed, and call the clean-up code if needed. If a
class supports Dispose or Close, and Dispose or Close was already called,
then Finalize should ignore the clean-up. Managed data doesn't need to be
manually cleaned up, but if managed code is using unmanaged data internally
(like various window API handles), then the class using these unmanaged
resource must provide a Dispose/Close method, and must do a final check for
clean-up of these unmanaged resources in Finalize.

-Rob Teixeira [MVP]
 

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