Memory leak with dynamic array

Don nospam at nospam.com
Mon Apr 12 09:40:06 PDT 2010


Joseph Wakeling wrote:
> Thanks to all again for the discussion, examples and explanations. :-)

[snip]
> My needs are in some ways quite narrow -- numerical simulations in
> interdisciplinary physics -- hence the C background, and hence the premium
> on performance.  They're also not very big programs -- simple enough for me
> to generally keep a personal overview on the memory management, even though
> with C++ that's usually all taken care of automatically (no new or delete
> statements if I can avoid it).
> 
> What I'm fairly confident about is that, given not too much time, D will
> become a _far_ preferable language for that kind of development.

There are quite a lot of us here with exactly that kind of background.

Something about the array issue -- D dynamic arrays are heavily geared 
towards algorithms which perform an initial allocation and afterwards 
avoid memory allocation entirely.
In D, such slicing algorithms are extremely clean, extremely fast, and 
memory safe.
In C++, it's much more difficult to write code in that manner. A 
straightforward translation from C++ will generally miss the benefits of 
D arrays, and you'll end up with slower code.

A kind of "Zen of D" is to use array slices as much as possible.



More information about the Digitalmars-d-learn mailing list