On Fri, 12 Apr 2013 04:14:15 -0400, Manu <turkey...@gmail.com> wrote:
On 12 April 2013 17:35, Steven Schveighoffer <schvei...@yahoo.com> wrote:
What would be your suggestion? string[string] is the built-in map type.
How do you pass an environment map without having some allocations?
I'd use string[].
You mean with format "a=b"? I suppose that's possible, though horrible to
work with before passing in. Plus what happens if you have ["a=b", "a=c"]
? AA's prevent these kinds of mistakes/contradictions.
I think someone suggested using a templated map type, that is probably a
good idea. Then you can provide whatever type you wish, with opIndex
capability.
toStringz is used liberally; alternatively, alloca() could allocate the
c-string's on the stack and zero terminate them there, passing a
pointer to
the stack string to the OS functions.
This would be a lot of effort for pretty much zero gain for the
majority of cases.
A trivial ... mixin template (?) could wrap it up, I don't see it
particularly less convenient than calling toStringz().
Perhaps there are other tools missing from phobos if this is somehow
hard...
alloca is hard to use, specifically because it can't be wrapped into a
function. I don't know how easy it would be to do with a mixin, I haven't
tried it.
Note that toStringz likely is going to avoid reallocation or copying if
possible -- it's very likely that a string already has a 0 after it, and
also very likely that if it doesn't, it has room to append a 0.
I still feel that if it can't be done easily, it over-complicates code for
very little gain.
As others have said too, this is an implementation detail. It can be done
as a later pull request if you feel up to making it work!
-Steve