|
Thanks N a v a n e e t h,
Great article!!
1.
I have answered the question by myself after reading it. It does not matter using new, what matters is whether the value type struct is in a reference type or standalone. In the MSDN sample, it is
standalone, and should be on stack, right?
http://msdn.microsoft.com/en-us/library/34yytbws(VS.80).aspx[^]
2.
In the link you referred, it is mentioned,
--------------------
There are a couple of exceptions to the above rules - captured variables (used in anonymous methods and lambda expressions) are local in terms of the C# code, but end up being compiled into instance variables in a type associated with the delegate created by the anonymous method. The same goes for local variables in an iterator block.
--------------------
I am confused about what means "The same goes for local variables in an iterator block."? )I have the knowledge about iterator and yield statement.)
regards,
George
|
|
|
|
|
George_George wrote: and should be on stack, right?
Yes, it should be on stack.
George_George wrote: "The same goes for local variables in an iterator block."?
Variables used with anonymous methods are compiled as instance variables and kept with the delegate type which created that. The same approach will be used for the local variables in an iterator block too, means it would be kept with the associated type.
|
|
|
|
|
Thanks N a v a n e e t h,
Sorry my English is not good. For the local variables in iterator, it will be expanded and chnaged to member variables of classes.
Since we are discussing stack/heap storage issues, does changing the local variable to member variable of a class will change the nature of the stack/heap location (I am confused about whether it impacts the variable itself or the real object the variable refers to)?
regards,
George
|
|
|
|
|
N a v a n e e t h wrote: Int32 is a built-in value type which don't inherit from System.ValueType
Huh? How did you find that out? Int32 of course inherits from ValueType - there's nothing special going on there.
N a v a n e e t h wrote: So it is easy and fast to refer and pass.
Easy, I don't know, but fast? Passing a value type with say, 5 fields, to a function, is definitely more expensive than passing a reference to a class (assuming the JITter doesn't do inlining).
|
|
|
|
|
George_George wrote: Great link! Why you can always find good stuff, do you have any magic powers?
Well, no Super-powers, see Iain Clarke sign to have some insight.
George_George wrote: BTW, three further questions,
N a v a n e e t h already gave very good answers.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
|
George_George wrote: the boxed type for all value type in C# are all System.Object?
The C# compiler simply emits the box[^] IL instruction - and that boxes it to an object of type System.Object.
|
|
|
|
|
Thanks Senthil,
Does it mean all value types of C# will be boxed to Object?
regards,
George
|
|
|
|
|
George_George wrote:
Does it mean all value types of C# will be boxed to Object?
Yes.
|
|
|
|
|
1)
Yes, the restriction exists in C# , not in the runtime.
2)
No delegates are nice.
But in C# they look like they are something different , c# provides special support for delegates.
while at CIL level, they are just classes that inherits from Delegate
|
|
|
|
|
Thanks Roger,
1. All value types are inherits from ValueType, and ValueType is inherits from Object, correct? I can not believe int and long are also inherits from ValueType/Object?
2. What do you mean "But in C# they look like they are something different , c# provides special support for delegates."? Any more description please?
regards,
George
|
|
|
|
|
George_George wrote: I can not believe int and long are also inherits from ValueType/Object?
Why? They are also equivalent to struct s, so why should they be any different?
If you've haven't already done it, download and install Reflector[^]. It allows you to disassemble .NET assemblies, including the framework ones - look for System.Int32 and sure enough, you'll find that it inherits from ValueType.
|
|
|
|
|
Thanks Senthil,
Your reply is clear. One further question, I think for primitive types, there are pairs of relationship, example int and Int32 are the same thing, only different in names. Is my understanding correct (I can not find answers from any books or search)?
regards,
George
|
|
|
|
|
George_George wrote: One further question, I think for primitive types, there are pairs of relationship, example int and Int32 are the same thing, only different in names. Is my understanding correct (I can not find answers from any books or search)?
Yes, int is just an alias for System.Int32, uint for UInt32 and so on. The C# compiler translates the names to the appropriate .NET datatypes.
|
|
|
|
|
Thanks Senthil,
Great to learn from you. So, a final confirmation, Object is the root for all value types (including primitive value types and user defined struct value types), and for all reference types, right?
regards,
George
|
|
|
|
|
George_George wrote: We can not inherit one value type from another, for example, we can not make a struct inherit from another struct; -- I think it means there is no inheritance or derivation for value types.
Yes. Value types are not possible to inherit. You can use interfaces and implement it on a structure though.
George_George wrote: All value types are inherits from ValueType, and ValueType is inherits from Object, seems value types could have inheritance or derivation?
Do you know System.ValueType is a class ? Not all value types are inherited from System.ValueType . There are some built in value types like integer. When you write a structure, it will be inherited from System.ValueType .
|
|
|
|
|
|
I have a Form with a Panel mainBackPanel. To mainBackPanel I add different panels say redPanel, greenPanel, bluePanel depending on key pressed, r, g, b respectively. Each panel has a different image (say tomatoes, trees, sky) and a transparent label.
Now when the panel changes, I see a small flicker on the area covered by the label.
mainBackPanel (to which the individual panels are added) is double buffered.
The code, in .NET 2.0, can be found here[^].
You will need to put 3 image files namely fb.jpg, mf.jpg and pl.jpg in bin/debug folder prior to running the app.
Please suggest how to get rid of the flicker.
Thanks
Sukhjinder
Looking for help on my OpenSource Media Player LetsYo
|
|
|
|
|
Before you do any processing on the images, use SuspendLayout[^] and when you're done use ResumeLayout.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
All KeyEvents are being handled by MainForm in the following method
void mainFormKeyUpHandler(Object o, KeyEventArgs kev)
{
if( kev.KeyCode == Keys.R )
{
this.mainBackPanel.Controls.Clear();
this.mainBackPanel.SuspendLayout();
this.mainBackPanel.Controls.Add(this.mainFormPanel);
this.mainBackPanel.ResumeLayout();
}
else
.
.
.
}
<br />
<br />
But the result is still the same. <br />
<br />
<div class="ForumSig">Looking for help on my OpenSource Media Player <a href="http://sukhjinder.cn/letsyo/contribute.html">LetsYo</a></div>
|
|
|
|
|
Move that suspend before Controls.Clear() as that may also cause some flickering. Might solve it for you.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
Tried that too. It doesn't work.
Looking for help on my OpenSource Media Player LetsYo
|
|
|
|
|
I searched the web and found many people having similar problems. Typical scene is you remove a control and add a new one. This causes a flicker. I searched the Internet and found some potential solutions but couldn't understand them much. Can you help me with it?
Solution #1[^]
Solution #2[^]
Solution #3[^]
Looking for help on my OpenSource Media Player LetsYo
|
|
|
|
|
Hi.
i'm developing an application in c#.
The first part is a typical application with forms, database queries, etc...
In a second phase, i need to design a panel with several buttons, with different captions, each button represent a complex vector shape with textures, for example a table, a computer, a tv...
When the user clicks on a button, a shape appears in a canvas. The user can drag and drop the shape and resize it.
If the user resize the shape, the texture must auto-adjust to the new size (tile effect).
In addition, it is necessary to implement a collision detector, to prevent "illegal positions".
f.e.: The table only can be placed in the floor and the tv only over the table, etc..
I need to chose an option (WPF, DIRECT2D, GRAPHICS CLASS ...)
1. ¿What option you recommend me?
2. Someone knows open source libraries or similar examples?
Thanks in advanced and sorry for my basic english
|
|
|
|
|
i am using the following code
System.IO.File.SetAttributes(Environment.GetFolderPath(
Environment.SpecialFolder.Cookies ).ToString(), FileAttributes.Normal);
DirectoryInfo directory = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Cookies));
if (directory.Exists)
DeleteFiles(directory);
public void DeleteFiles( DirectoryInfo directory)
{
FileInfo[] info = directory.GetFiles();
foreach (FileInfo file in directory.GetFiles())
{
try
{
System.IO.File.SetAttributes(file.FullName, FileAttributes.Normal);
file.Delete();
}
catch (Exception ex)
{
}
}
foreach (DirectoryInfo dir in directory.GetDirectories())
{
try
{
DeleteFiles(dir);
}
catch (Exception ex)
{
}
}
}
This code is deleting all files in the Cookie folder but the problem is index.dat file remains there it gives error
Used by another person or program
What should i do to delete that file
Thanks
|
|
|
|