Help with some terminology

Help with some terminology

Post by Joel » Mon, 29 Jan 2007 23:22:51


(1) Can anyone please tell me the exact meaning of primitive types in
the MSIL context.

(2) Also what is the meaning of the world inline?

(3) What is the meaning of the statement: "You should bear in mind,
however, that decimal is not implemented under the hood as a primitive
type, so using decimal will have a performance impact on your
calculations." ?

(4) What makes value types work faster than reference types. The only
speed difference is during object creation right? Value types on stack
are created faster than creating a reference type on the heap. After
this, what makes one faster than the other?

Thanks

Joel
 
 
 

Help with some terminology

Post by David Brow » Tue, 30 Jan 2007 00:01:56


Homework?

David

 
 
 

Help with some terminology

Post by Joel » Tue, 30 Jan 2007 00:45:11

> Homework?

I'm afraid I've done my homework David. I've looked for answers to the
above questions but still don't feel very good about them so thought
of asking.

Please excuse me. :|

Joel
 
 
 

Help with some terminology

Post by David Brow » Tue, 30 Jan 2007 03:13:38


"Joel" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...

Ok,

Here's some pointers


AFAIK "primitive types" has no exact technical meaning in the MSIL context.
In general "primitive types" are used to refer either to the built-in value
types, or to the types which represent processor primitives in the platform.
These always include things like 32bit integers, floats, booleans, etc.


In C++ declaring and defining a function as 'inline' instructs the compiler
to expand function calls to this function and place a copy of the functions
body in place of the method call. Essentially 'inline' is a copilier
optimization exposed in the programming language. This is consistent with
C++'s design philosophy, but not with C#. In C# such optimizations are left
up to the discresion of the Just-in-Time compiler.



Adding two int's or two float's takes only a single processor instruction.
Adding two decimals might take thousands. So for scientific and technical
applications where number-crunching speed matters, you should take this into
account. For general computation, the performance difference is unlikely to
be noticeable.


In .NET reference type allocation is very fast, and so allocation speed is
the least of the performance advantages for value types. The performance
benefits of value types are:

Locality
There is a bottleneck between the processor and main memory, and code
operating on data that is bunched locally together is more efficient. Value
types allocated on the stack promote locality in your code by helping to
concentrate the memory footprint of your program on the top part of the
stack, rather than having data scattered around the managed heap. Although
heap allocation does have some locality in .NET due to the fact that managed
heap allocations always occur at the 'end' of the heap, and large object
allocations are segregated to another heap.

Copy-by-value Semantics
For small types, passing the type value is minimally more expensive than
passing a pointer, and you save both the operation and the memory read of
dereferencing the pointer when accessing the value.

Deallocation Cost
This is the big one. Value types on the stack are deallocated by simply
moving back the stack pointer at the end of the scope. Reference types are
garbage collected.

Allocation Cost
Heap allocation is fast, but during a heap allocation you might trigger
a garbage collection and have to wait until after the collection is done for
the allocation to succeed.


However, the sum total of all these performance differences doesn't amount
to much for most programs. In general you should use the types and
techniques optimize the simplicity and understandability of the program, and
only optimize for performance when you are dealing with some special
performance requirement.

David

 
 
 

Help with some terminology

Post by Joel » Tue, 30 Jan 2007 03:59:16

> Here's some pointers

Thanks a lot David. :-)

Joel
 
 
 

Help with some terminology

Post by Joel » Tue, 30 Jan 2007 03:59:40

> Here's some pointers

Thanks a lot David. :-)

Joel