View previous topic :: View next topic |
Author |
Message |
Eelco
Joined: 28 Jun 2004 Posts: 10 Location: Netherlands
|
Posted: Fri Jul 02, 2004 7:48 am Post subject: Classes and structs |
|
|
objects in D are always created and managed by reference. what exactly are the consequences of this?
does this mean a Vector3 class will be slow in inner loops? do i need to abbandon elegance altogether and use a struct for things like that? i saw this mentioned somewhere, but how much of this is true? |
|
Back to top |
|
|
Hohums
Joined: 08 Apr 2004 Posts: 71 Location: Western Australia
|
Posted: Sun Jul 11, 2004 6:40 am Post subject: |
|
|
If youâ?re going to create something like a 3d vector (which has been created so many times for D I don't know why its not in the standard yet <g>) then yes, use a struct. Note that now that D has mixins you can get all the inheritance you need for things like vectors. Things like virtual functions that you get from classes should not be used for things like vectors.
Thatâ?s the thing I like about struct in D. You are guaranteed to get a simple structure with no Vtable or any other unnecessary junk (in this case) and user can't accordantly do so.
As with classes, your passing around pointers which in some cases can be a slow down. However (in the future) because the compiler knows your passing around a ref object, it should be able to optimise circumstances where it can find no side effects in doing so. _________________ http://badmama.com.au/~anderson/ |
|
Back to top |
|
|
|