[OT] Previously: DMD - Windows -> C# in gamedev

bearophile bearophileHUGS at lycos.com
Sat Jan 7 10:59:29 PST 2012


Manu:

> The tendency to encourage use of dynamic arrays will be a major problem.

I don't know how much big that problem will be, D dynamic arrays are quite handy, but I agree that static arrays need to be encouraged more in D (and currently most algorithms of Phobos don't work with static arrays (you need to slice them first)).

Currently even this code with a stack-allocated fixed size array causes a heap allocation (DMD):

void main() {
    int[2] a = [1, 2];
}

ASM, optimized build:

__Dmain comdat
    push EAX
    push EAX
    mov EAX,offset FLAT:_D12TypeInfo_xAi6__initZ
    push EBX
    push 8
    push 2
    push EAX
    call near ptr __d_arrayliteralTX ; heap allocation
    add ESP,8
    mov EBX,EAX
    mov dword ptr [EAX],1
    mov ECX,EBX
    push EBX
    lea EDX,0Ch[ESP]
    mov dword ptr 4[EBX],2
    push EDX
    call near ptr _memcpy
    add ESP,0Ch
    xor EAX,EAX
    pop EBX
    add ESP,8
    ret


I have suggested to add a safer version of VLAs to avoid some heap-allocated dynamic arrays:
http://d.puremagic.com/issues/show_bug.cgi?id=5348

Most people here seem to not care of the Ada language, but if you take a look at Ada code you see how often it doesn't use heap allocations.

Bye,
bearophile


More information about the Digitalmars-d mailing list