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

Dynamic array elements initialization

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



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Tue Jul 15, 2008 7:01 am    Post subject: Dynamic array elements initialization Reply with quote

Dynamic arrays in D are initialized with default value - for int it is 0. It leads to significant performance loose - when I make an array of let's say 10 million elements - it is senseless to have all of them equaled to 0 - because after initialization I am going to assign some value to each element. Compared to C++ - it is really slow. Is there any way to allocate memory for dynamic array without inilializing in D? For large data processing I think it's not to good, although D tends to be a system programming language Sad
Back to top
View user's profile Send private message
MaKo



Joined: 12 Jul 2008
Posts: 5

PostPosted: Tue Jul 15, 2008 1:07 pm    Post subject: Reply with quote

I'm not sure about uninitialized arrays in D, but why don't you make a small C file, which allocates that large buffer? BTW, is there malloc/free in std.c.* -somewhere?
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Tue Jul 15, 2008 3:09 pm    Post subject: Re: Dynamic array elements initialization Reply with quote

eldar wrote:
Dynamic arrays in D are initialized with default value - for int it is 0. It leads to significant performance loose - when I make an array of let's say 10 million elements - it is senseless to have all of them equaled to 0 - because after initialization I am going to assign some value to each element. Compared to C++ - it is really slow. Is there any way to allocate memory for dynamic array without inilializing in D? For large data processing I think it's not to good, although D tends to be a system programming language Sad
Have you tried "Void Initializations" as described on the Declarations page (D 1.0 / D 2.0)?

(Edited to fix typo.)
Back to top
View user's profile Send private message AIM Address
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