TempAlloc review starts now

Daniel Gibson metalcaedes at gmail.com
Mon Jun 6 12:55:02 PDT 2011


Am 06.06.2011 21:40, schrieb Steven Schveighoffer:
> On Mon, 06 Jun 2011 15:10:49 -0400, dsimcha <dsimcha at yahoo.com> wrote:
>> == Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
>>> TempAlloc.malloc:
>>> I don't like void * as a return value.  Would it not be more appropriate
>>> to use at least void[]?  I'd suggest actually for malloc to take a
>>> template parameter of the type to return, defaulting to void.  i.e.:
>>> T[] malloc(T = void)(size_t size);
>>
>> Here I'm going to have to strongly disagree.  I want to keep
>> TempAlloc.malloc
>> consistent with GC.malloc and core.stdc.stdlib.malloc.
> 
> I can understand that point of view.  I just would like to avoid using
> pointers where it's not necessary.  And I especially like this:
> 
> auto buf = TempAlloc.malloc!uint(1024);
> 
> better than this:
> 
> auto buf = (cast(uint *)TempAlloc.malloc(1024 * uint.sizeof))[0..1024];
> 
> I would actually argue that GC.malloc might be better off returning
> void[].  You can always get the pointer with .ptr.
> 

I agree. Why does GC.malloc return void* anyway?
In D1 std.gc.malloc returns void[], so GC.mallocs behaviour seems like a
step backwards to me.

Cheers,
- Daniel


More information about the Digitalmars-d mailing list