View previous topic :: View next topic |
Author |
Message |
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Tue Jul 15, 2008 7:01 am Post subject: Dynamic array elements initialization |
|
|
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 |
|
Back to top |
|
|
MaKo
Joined: 12 Jul 2008 Posts: 5
|
Posted: Tue Jul 15, 2008 1:07 pm Post subject: |
|
|
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 |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
Posted: Tue Jul 15, 2008 3:09 pm Post subject: Re: Dynamic array elements initialization |
|
|
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 | Have you tried "Void Initializations" as described on the Declarations page (D 1.0 / D 2.0)?
(Edited to fix typo.) |
|
Back to top |
|
|
|