Structure vs Class - Performance Gain? 
Author Message
 Structure vs Class - Performance Gain?

Is there a performance gain to be had by using a Structure instead of a
Class?

I can't see any other reason to use a Structure over a Class, given that a
Structure has cut-back functionality.  Is it just a VB
backward-compatibility thing, or is there some tricky little distinction
between these things?

Thanks for anyone's insights.
--
Phil (New Zealand - Aotearoa)



Sun, 30 Jan 2005 11:10:09 GMT  
 Structure vs Class - Performance Gain?
Please ignore this posting...I have found a corresponding thread on this
group that covers the topic [thanks Cowboy (aka Gregory)]

Sorry.
--
Phil (New Zealand - Aotearoa)


Quote:
> Is there a performance gain to be had by using a Structure instead of a
> Class?

> I can't see any other reason to use a Structure over a Class, given that a
> Structure has cut-back functionality.  Is it just a VB
> backward-compatibility thing, or is there some tricky little distinction
> between these things?

> Thanks for anyone's insights.
> --
> Phil (New Zealand - Aotearoa)



Sun, 30 Jan 2005 11:17:09 GMT  
 Structure vs Class - Performance Gain?
Phil:

I would ignore this, but many who might find some use in this answer might
miss the older post, and I might drone on about something more important.

Structures can provide a perf benefit when the object is a good stack object
(generally small). To move all classes to structs, however, will cause a
major problem, as you will be putting everything on stack. I have seen an
example (although it was called an application) that would run out of stack
space, as everything was a structure.

In general, stick to classes, and use structures primarily like you would
use a UDT in Visual Basic 6 (and prior). You may find some instances to
break this rule, but it will do well as a rule of thumb.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Author: ADO.NET and XML: ASP.NET on the Edge

****************************************************************************
****
Think outside the box!
****************************************************************************
****

Quote:
> Is there a performance gain to be had by using a Structure instead of a
> Class?

> I can't see any other reason to use a Structure over a Class, given that a
> Structure has cut-back functionality.  Is it just a VB
> backward-compatibility thing, or is there some tricky little distinction
> between these things?

> Thanks for anyone's insights.
> --
> Phil (New Zealand - Aotearoa)



Sun, 30 Jan 2005 21:54:35 GMT  
 Structure vs Class - Performance Gain?
Classes are reference objects and are managed by the garbage collector.
Created on the stack
Structs are value objects and are not managed by the garbage collector.
Created in the heap

Also there are some {*filter*} gotchas when intermixing the two unless you have
some guaranteed naming convention to tell the two apart.

You can end up with boxing problems when passing structs around etc.

My suggestion is to always use classes, unless you 100% understand the
implications of how objects are really passed and how boxing works. (Note
all these also apply to C#)


Quote:
> Is there a performance gain to be had by using a Structure instead of a
> Class?

> I can't see any other reason to use a Structure over a Class, given that a
> Structure has cut-back functionality.  Is it just a VB
> backward-compatibility thing, or is there some tricky little distinction
> between these things?

> Thanks for anyone's insights.
> --
> Phil (New Zealand - Aotearoa)



Mon, 31 Jan 2005 01:38:45 GMT  
 Structure vs Class - Performance Gain?
Hi Jeff,

That's the kind of advice I want to hear.  I'd much prefer to stick with
classes all the time, I was just concerned with any potential performance
hit Classes may incur over Structures [but then again, that's what the .NET
Framework is supposedly great at.....building up and tearing down millions
of objects very rapidly - at least that what I heard.]

Thank you very much for your words.
--
Phil (New Zealand - Aotearoa)


Quote:
> Classes are reference objects and are managed by the garbage collector.
> Created on the stack
> Structs are value objects and are not managed by the garbage collector.
> Created in the heap

> Also there are some {*filter*} gotchas when intermixing the two unless you have
> some guaranteed naming convention to tell the two apart.

> You can end up with boxing problems when passing structs around etc.

> My suggestion is to always use classes, unless you 100% understand the
> implications of how objects are really passed and how boxing works. (Note
> all these also apply to C#)



> > Is there a performance gain to be had by using a Structure instead of a
> > Class?

> > I can't see any other reason to use a Structure over a Class, given that
a
> > Structure has cut-back functionality.  Is it just a VB
> > backward-compatibility thing, or is there some tricky little distinction
> > between these things?

> > Thanks for anyone's insights.
> > --
> > Phil (New Zealand - Aotearoa)



Tue, 01 Feb 2005 05:37:32 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Performance: Compiled Classes as DLL vs Classes in Application Code

2. Performance: Compiled Classes as DLL vs Classes in Application Code

3. Performance: Compiled Classes as DLL vs Classes in Application Code

4. Structures vs. classes

5. Structure vs Class

6. Memory (Structure vs Class)

7. Performance gain?

8. Are there performance gains from normalizing data?

9. 2.5 to 2.6SP1 performance gain

10. ADO's Performance vs DAO's Performance

11. Serializing a Class within a Class (Previously Structures)

12. Class Libraries vs. Classes

 

 
Powered by phpBB® Forum Software