D - how dynamic arrays work?
- Pavel Minayev (11/11) Dec 21 2001 I wonder how dynamic arrays are implemented in D. Do
- Russell Borogove (7/20) Dec 21 2001 I think that Walter indicated a while back that darrays
I wonder how dynamic arrays are implemented in D. Do they reallocate themselves each time new element is added? Or do they reserve memory in larger blocks, so that several (how many?) consequent appends would not require reallocation, like std::vector does? I understand that it's implementation-defined, still it would be useful to know at least how your compiler works; I just want to decide if I can use dynamic arrays to generate data dynamically in the memory as is fast enough, or I have to make a wrapper class that'd allocate memory in larger blokes.
Dec 21 2001
Pavel Minayev wrote:I wonder how dynamic arrays are implemented in D. Do they reallocate themselves each time new element is added? Or do they reserve memory in larger blocks, so that several (how many?) consequent appends would not require reallocation, like std::vector does? I understand that it's implementation-defined, still it would be useful to know at least how your compiler works; I just want to decide if I can use dynamic arrays to generate data dynamically in the memory as is fast enough, or I have to make a wrapper class that'd allocate memory in larger blokes.I think that Walter indicated a while back that darrays generally alloc in power-of-two steps up to a given size and then linearly after that, so go ahead and build your darrays one element at a time and let the compiler take care of you. -RB
Dec 21 2001