TempAlloc Overhaul
dsimcha
dsimcha at yahoo.com
Sat Jun 11 16:55:58 PDT 2011
On 6/11/2011 7:04 PM, bearophile wrote:
> dsimcha:
>
>> I've overhauled my TempAlloc proposal based on some of the suggestions I've received.
>
> It's improved :-)
>
>
>> 3. Make alignedMalloc and friends private for now, again to make the proposal more tightly focused.<
>
> They are useful so I'd like such alignedCMalloc / free to be generally visible, with a template argument to specify the desire alignment, that defaults to 16. But I agree it's better to not put it in std.tempalloc.
Eventually, I may make them visible. For now, I want to make this
proposal tightly focused.
>
>
>> The first segment of the TempAlloc stack is allocated lazily, so no space is allocated in any thread that does not use TempAlloc.<
>
> Is this causing any slowdown in the usage of the memory?
Technically yes, because every call to anything TempAlloc-related has to
compare a pointer to null. In practice, I don't think this is ever a
significant slowdown.
>
>
>> static void* malloc(size_t nbytes);<
>
> I think the docs have to say this is aligned memory (and there is no way to specify a smaller alignment).
I guess I could put in the docs that it's 16-byte aligned, but there are
two reasons why specifying smaller alignment isn't allowed:
1. It would clutter the API with a feature that that is very
infrequently used.
2. It would probably have a performance penalty, whereas rounding up
all allocations to a hard-coded power of two is dirt-cheap.
>
>
>> In this case sizes may be specified for any number of dimensions from 1 to the number in T.<
>
> Isn't it bug prone to allow to specify a number of sizes less than the number of dimensions?
I don't see why it is, though perhaps I should include this as an
example, too:
// Allocate an array of 100 double[]'s and don't initialize them.
double[][] matrix = TempAlloc.newArray!(double[][])(100);
// Use it.
matrix[0] = TempAlloc.newArray!(double[])(100);
>
>
>> double[] foo = TempAlloc.newArray!(double[])(100);
>
> A little usability problem: an array of array of double or just array of double?
Yeah, you might be getting a little confused because I actually changed
this in the overhaul. Used to be that you would write:
double[] foo = newStack!double(100);
The reason I did this was to make the multidimensional syntax sane.
>
> Bye,
> bearophile
More information about the Digitalmars-d
mailing list