|
By using structs, you can create objects that behave like the built-in types and enjoy their benefits as well.
when you instantiate a struct, it gets created on the stack. This will yield performance gains.
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
vikas amin wrote: objects that behave like the built-in
Such as?
vikas amin wrote: enjoy their benefits
Which benefits?
vikas amin wrote: it gets created on the stack. This will yield performance gains
So, if I create a struct that has, say, 100 ints. That will be more performant than a class with the same?
What if I need to pass that object around? Say I need to pass it into a method or two?
|
|
|
|
|
Well of course, a nice neat stack is way better than a big untidy heap any day.
|
|
|
|
|
PIEBALDconsult wrote: Well of course, a nice neat stack is way better than a big untidy heap any day.
Nice reply!
|
|
|
|
|
Colin Angus Mackay wrote: So, if I create a struct that has, say, 100 ints. That will be more performant than a class with the same?
What if I need to pass that object around? Say I need to pass it into a method or two?
I believe that unless you use the 'ref' keyword, passing structs results in cloning, much like passing a string or int, so in this case it would probably be less performant if there is a lot of passing.
I'm not sure how the 'ref' keyword works on structs, but if it's like the built-in types this should avoid the above problem.
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
vikas amin wrote:
objects that behave like the built-in
Such as?
--> By build-in I mean value type .
vikas amin wrote:
enjoy their benefits
Which benefits?
--> benefits of value type .
vikas amin wrote:
it gets created on the stack. This will yield performance gains
So, if I create a struct that has, say, 100 ints. That will be more performant than a class with the same?
What if I need to pass that object around? Say I need to pass it into a method or two?
--> Same solution don’t work in every scenario .
Its a fact that if you want to pass a large object to a method,
C# can use Ref keyword
--> What if you have 100 user defined variables to be created for a
short time say say for single calculation ,its a fact that Heap-
managed objects take more time to allocate, access, and update
than stack-managed ones
so you can use structure to speed up such process , i don't deny
that there are many more way to improve performance .
--> while using unmanaged code or say when use pinvoke to call native
code you set the structure attributes for performance
Thanks for the comments , please let me know if I am wrong some where
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
vikas amin wrote: By using structs, you can create objects that behave like the built-in types
What he means is that you can create types with value type semantics.
vikas amin wrote: when you instantiate a struct, it gets created on the stack.
That is an over-simplification that can get confusing.
A struct is stored as inline data. If declared as a local varaible it's allocated on the stack, but if declared as a member of another type, it's allocated where that type is allocated. As a member of a class, it will be allocated on the heap along with the other members of that class instance.
vikas amin wrote: This will yield performance gains.
No, this may yield performance gains, if the struct is sufficiently small, and used in such a way that it takes advantage of how value types work.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
vikas amin wrote:
This will yield performance gains.
Guffa wrote:
No, this may yield performance gains
Yes you are right i should be "MAY" insted of "WILL" ,
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
Consider this example class and struct
public class MyClass
{
public int Variable;
}
public struct MyStruct
{
public int Variable;
} They are identical apart from being a class/struct.
Now try this on these:
MyClass myClassA = new MyClass();
myClassA.Variable = 5;
MyClass myClassB = myClassA;
myClassB.Variable = 3;
Console.WriteLine(myClassA.Variable);
MyStruct myStructA = new MyStruct();
myStructA.Variable = 5;
MyStruct myStructB = myStructA;
myStructB.Variable = 3;
Console.WriteLine(myStructA.Variable); When the value of Variable is changed in myClassB it also changes the value of Variable in myClassA. This is because when we did MyClass myClassB = myClassA; it didn't copy the value in A to B - it referenced B to the same memory location that A was pointing to. That's passing by reference.
Structs are passed by value so a copy of myClassA is made and myClassB points to the copy.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Structure:
Lightweight object
Structure is allocated in Stack and passed as value type
Structure can implement interfaces
Instance can be created with new key word or not
Structure can contain Constructor
Class:
Simply it’s a abstract model used to define new data type
Fields is nothing but data in Class may be variable or other class object
Reference or object is created in heap
1. Referance Type:
Inherited from System. Object
Reference to memory location
Can be set to null
very much pointers in other languages
2. Value Type :
Inherited from System.Valuetype
Reference to value
Reference and value type both have advantage and disadvantage but it depends on
your requirement.
Thanks
Raja.S
|
|
|
|
|
I have used the following code in my media player for several years now and have incurred no problems. I recently updated to Mediaplayer 11 and this code is no longer recognized.
private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (e.newState == 8 || e.newState == 1)
{
this.WMPlayer.Size = new System.Drawing.Size(325, 64);
}
if (e.newState == 8)
{
timer3.Interval = 5000;
timer3.Enabled = true;
}
}
Does anyone have an explanation and solution?
Complete source code that works under Mediaplayer 10 is available from my web site:
http://electriac.googlepages.com/wmplayer.exe[^]
modified on Tuesday, August 19, 2008 4:57 PM
|
|
|
|
|
I have uninstalled Mediaplayer 11 and reinstalled Mediaplayer 10 and all is well. So does this mean my program must use Mediaplayer 10!???
|
|
|
|
|
I have an application where I incremented the version on one of the projects now when I try and run it I get an Invalid Caste exception when I try to cast an object to a class that it is (specifically I have a class that implements an interface and I'm trying to cast it to that interface). I get the little message that pops up warning me that some assembly was compiled in release mode so I won't have debugging or some such. This pop up lists the assembly as 1.0.0.0 when I have set the assembly to 1.1.0.0. Why won't it use the new version? I have already removed all references and readded them in all projects that are dependent on this assembly.
|
|
|
|
|
Here is what they do in the Web.config to rebind the MS AJAX stuff, it should work the same for Castle if the assebmliesare compatible.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
xacc.ide - now with TabsToSpaces supportIronScheme - 1.0 alpha 4a out now (29 May 2008)
|
|
|
|
|
Thanks for the suggestion, I actually just figured it out. There is an XML file that lists all a bunch of types for this Query Builder tool we have and in this XML file it specifies the version, so all I had to do was update the version number in this file and it started working fine.
|
|
|
|
|
hi all.
i saw a application that show all of a .net application code from it exe file.
how can i lock my .net exe file?
sepel
|
|
|
|
|
sepel wrote: i saw a application that show all of a .net application code from it exe file.
These types of program are called disassemblers. Next, they dont show you all the code but the structure and not the logic.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Manas Bhardwaj wrote: Next, they dont show you all the code but the structure and not the logic.
Actually, they do show the logic. What they don't show is the exact original source code. There are no comments, some of the variable names may not be correct and so on. However, all the logic is still there.
|
|
|
|
|
Manas Bhardwaj wrote: they dont show you all the code but the structure and not the logic.
Not true. Reflector does show everything.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Paul Conrad wrote: Not true. Reflector does show everything.
I wish it would show me assemblies without CLI headers
Mark Brock
"We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen
Click here to view my blog
|
|
|
|
|
You can't lock your code, what you're looking for is Code Obfuscators (sp?).
Tools like Reflector use the IL to rebuild what your code does, the logic is mainly there but it definitely won't be what you originally wrote.
|
|
|
|
|
hammerstein05 wrote: Code Obfuscators
I second that. I've seen the one from RustemSoft actually make Reflector crash when doing a very aggressive obfuscation.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
As in the one reply you got, I'd second hammerstein's suggestion of looking into an obfuscater. Though they are not 100% effective, they do make it difficult to reverse engineer your code.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I agree. I know many of the people I work with should be embarrassed by their work and should not want people to see it. Obfuscation is a good way to hide that embarrassing source code. ;)
led mike
|
|
|
|
|
funny !
|
|
|
|