Hidden allocations (Was: Array literals REALLY should be immutable )

Bill Baxter wbaxter at gmail.com
Thu Nov 12 09:26:44 PST 2009


2009/11/12 Denis Koroskin <2korden at gmail.com>:

> // untested
> void mkdirRecurse(string path) {
>    char* buffer = alloca(path.length);
>    memcpy(buffer, path);
>
>    foreach (i, c; buffer[0..path.length]) {
>        if (c == '/') {
>            buffer[i] = 0;
>            mkdir(buffer);
>            buffer[i] = '/';
>        }
>    }
> }
>
> There are a lot of functions that allocate without a clear reason.)

I'm pretty sure the reason is that it means library code that's easier
to write, understand and maintain.

But yeh, if you give me the choice of two different functions, one
that allocates and one that doesn't, otherwise identical, I'll pick
the non-allocating version.

--bb



More information about the Digitalmars-d mailing list