473,379 Members | 1,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Generic Type Instantiation Again

From <http://msdn2.microsoft.com/en-us/library/f4a6ta2h(en-US,VS.80).aspx>:

| As with the previous use of the Stack<T> class created with the Order
| type, another instance of the specialized Stack<T> class is created,
| and the pointers contained therein are set to reference an area of
| memory the size of a Customer type.

I don't quite get this. Where in memory do these changes (the pointers
getting set) take place?
Dec 7 '05 #1
8 1607
Cool Guy,

This is handled by the CLR. The CLR will create a separate type
definition for every distinct combination of value types used in a generic
type as type parameters. So, if you have Stack<int> and Stack<byte>, the
CLR will actually create two type definitions.

If you have a Stack<Customer> and Stack<Order> where Customer and Order
are reference types, then the CLR creates one type definition to use between
the two of them. The reason for this is that you are not dealing with the
actual memory that instances of the type take up, but rather, references,
which are all one, constant size.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Cool Guy" <co*****@abc.xyz> wrote in message
news:1r***************@cool.guy.abc.xyz...
From
<http://msdn2.microsoft.com/en-us/library/f4a6ta2h(en-US,VS.80).aspx>:

| As with the previous use of the Stack<T> class created with the Order
| type, another instance of the specialized Stack<T> class is created,
| and the pointers contained therein are set to reference an area of
| memory the size of a Customer type.

I don't quite get this. Where in memory do these changes (the pointers
getting set) take place?

Dec 7 '05 #2
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote:
This is handled by the CLR. The CLR will create a separate type
definition for every distinct combination of value types used in a generic
type as type parameters. So, if you have Stack<int> and Stack<byte>, the
CLR will actually create two type definitions.

If you have a Stack<Customer> and Stack<Order> where Customer and Order
are reference types, then the CLR creates one type definition to use between
the two of them. The reason for this is that you are not dealing with the
actual memory that instances of the type take up, but rather, references,
which are all one, constant size.


That much, I understand, but the part of the article I quoted in the OP
threw me. I'm trying to figure out precisely which pointers are set*, in
order to understand what goes on under the hood.

* The quote was: "[...] the pointers contained therein are set to reference
an area of memory the size of a Customer type."
Dec 7 '05 #3
Cool Guy,

Basically, the references are references to type Customer. However,
from the generic type's point of view, this doesn't matter. The only thing
the generic type cares about, if it is a reference type, is the fact that
because it is a reference type, the size requirements for fields and whatnot
are the same.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Cool Guy" <co*****@abc.xyz> wrote in message
news:db***************@cool.guy.abc.xyz...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote:
This is handled by the CLR. The CLR will create a separate type
definition for every distinct combination of value types used in a
generic
type as type parameters. So, if you have Stack<int> and Stack<byte>, the
CLR will actually create two type definitions.

If you have a Stack<Customer> and Stack<Order> where Customer and
Order
are reference types, then the CLR creates one type definition to use
between
the two of them. The reason for this is that you are not dealing with
the
actual memory that instances of the type take up, but rather, references,
which are all one, constant size.


That much, I understand, but the part of the article I quoted in the OP
threw me. I'm trying to figure out precisely which pointers are set*, in
order to understand what goes on under the hood.

* The quote was: "[...] the pointers contained therein are set to
reference
an area of memory the size of a Customer type."

Dec 7 '05 #4
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote:
Basically, the references are references to type Customer. However,
from the generic type's point of view, this doesn't matter. The only thing
the generic type cares about, if it is a reference type, is the fact that
because it is a reference type, the size requirements for fields and whatnot
are the same.


Yep, I understand that. :) I'm trying to work out precisely which
pointers are being spoken about in the following:

| [...]
| and the pointers contained therein are set to reference an area of
| memory the size of a Customer type.

The pointers contained in what?
Dec 7 '05 #5
I wrote:

[snip]

Just to clarify -- I realise that it's not essential to know this in
general; I'm simply asking so that I can work what goes on under the hood
in this situation.
Dec 7 '05 #6
I wrote:

[snip]

This is the kind of thing I'm talking about -- from
<http://www.artima.com/intv/generics2.html>:

| Anders Hejlsberg: [...] For all reference types
| we share the code, because they are representationally
| identical. It's just pointers.
|
| Bruce Eckel: And you just need to cast.
|
| Anders Hejlsberg: No, you don't actually. We can
| share the native image, but they actually have
| separate VTables. [...]

Now, *this* makes sense, but what I don't understand is where the

"the pointers contained therein are set to reference an area of memory
the size of a Customer type"

thing fits it. Any ideas?
Dec 7 '05 #7
>Now, *this* makes sense, but what I don't understand is where the

"the pointers contained therein are set to reference an area of memory
the size of a Customer type"

thing fits it. Any ideas?


It sounds plain wrong (or just poorly worded) to me. This part is more
like a description of what happens when you create an instance of the
type parameter T. That doesn't happen when the Stack type is created.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 7 '05 #8
Mattias Sjögren <ma********************@mvps.org> wrote:
Now, *this* makes sense, but what I don't understand is where the

"the pointers contained therein are set to reference an area of memory
the size of a Customer type"

thing fits it. Any ideas?


It sounds plain wrong (or just poorly worded) to me. This part is more
like a description of what happens when you create an instance of the
type parameter T. That doesn't happen when the Stack type is created.


Thanks!
Dec 8 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Joanna Carter \(TeamB\) | last post by:
I want to be able to use a generic type, bind its generic parameters to specific type(s) and then hold newly created instances in a list of generic ypes. Sort of like this : class Agent<T> {...
4
by: Cool Guy | last post by:
I don't understand the third paragraph under the heading 'Generic type instantiations' on <http://msdn.microsoft.com/vcsharp/2005/overview/language/generics/>: | The .NET Common Language Runtime...
6
by: Dan Holmes | last post by:
I have a class that i need a constraint of int, string, float or bool. I have tried the following but can't make VS accept it. I read the docs and they showed that any value type can be used...
3
by: Boris | last post by:
I have a class which should like this ideally: generic <typename T> public ref class ManagedClass { T ^managedMember; UnmanagedClass<U*unmanagedMember; }; I actually would like to specify...
7
by: Dave | last post by:
I've got these declarations: public delegate void FormDisplayResultsDelegate<Type>(Type displayResultsValue); public FormDisplayResultsDelegate<stringdisplayMsgDelegate; instantiation:...
3
by: Peter K | last post by:
Hi I have an interface for a "factory" defined like this: public interface IDeviceFactory<T: IDisposable { T GetDevice(); }
11
by: paul.gibson | last post by:
A simple code example is easier than trying to describe the issue. I have: public class myClassA {
11
by: Scott Stark | last post by:
Hello, The code below represents a singly-linked list that accepts any type of object. You can see I'm represting the Data variable a System.Object. How would I update this code to use...
8
by: Advait Mohan Raut | last post by:
Hello, I am using VC# 2005 ; C# 2.0 I am working on the performance measurement tool. For that I need my code to call user defined method along with its parameters. For that should I use a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.