ZY Zhou <> changed:

           What    |Removed                     |Added
                 CC|                            |

--- Comment #1 from ZY Zhou <> 2009-09-23 01:38:43 PDT ---
(In reply to comment #0)
> It appears that adding an element to an associative array always triggers a
> memory allocation.  Especially in multithreaded code, this is inefficient.  It
> would be nice if associative arrays had a .reserve(size_t n) property, which
> reserved enough space for n objects, and stored the capacity internally.  The
> idea is that, until the reserve buffer is exhausted, no interaction of any 
> kind
> with the GC would be needed to add an element to the AA.

It's not all about memory

int[int] a;
foreach(i;0..20_000_000) a[i] = i; //takes 2 _minutes_
foreach(i;0..20_000_000) a[i] = i; //do it again, only 2 seconds

60 times slower.
If it's memory allocation problem, the result should be similar to Dynamic

int[] t;
foreach(i;0..20_000_000) t ~= i; // 2 seconds
foreach(i;0..20_000_000) t[i] = i; // 0.3 seconds

I guess AA rehashs the whole array when capacity changes, and rehashing is much
slower than memory allocation.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to