FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Classes and structs

 
Post new topic   Reply to topic     Forum Index -> General
View previous topic :: View next topic  
Author Message
Eelco



Joined: 28 Jun 2004
Posts: 10
Location: Netherlands

PostPosted: Fri Jul 02, 2004 7:48 am    Post subject: Classes and structs Reply with quote

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
View user's profile Send private message
Hohums



Joined: 08 Apr 2004
Posts: 71
Location: Western Australia

PostPosted: Sun Jul 11, 2004 6:40 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> General All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group