"Joel" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
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
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:
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.
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.
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
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