[Issue 13159] std.socket.getAddress allocates once per DNS lookup hit
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Jul 19 09:25:34 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13159
Jakob Ovrum <jakobovrum at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakobovrum at gmail.com
--- Comment #2 from Jakob Ovrum <jakobovrum at gmail.com> ---
I already posted a PR for this BTW:
https://github.com/D-Programming-Language/phobos/pull/2351
(In reply to Orvid King from comment #1)
> Assuming that infos has a length property, it would be better yet to simply
> do:
>
> auto infos = getAddressInfo(hostname, service);
> auto results = new Address[infos.length];
This would allocate even when infos.length is 0.
> Which would result in exactly the amount of memory needed being allocated,
> and only 1 allocation being done.
`getAddressInfo` allocates too, and easily more than once, so that wouldn't be
quite true.
> I would also suggest the possibility of adding an OutputRange based version.
We can do better - a version that returns the results as a lazy forward range.
The most underlying data structure here is a singly linked list. We can use
reference counting to ensure the list is freed (freeaddrinfo). It's a much
heavier change though so I'm not going to do it in PR #2351.
--
More information about the Digitalmars-d-bugs
mailing list