GC vs. Manual Memory Management Real World Comparison

bearophile bearophileHUGS at lycos.com
Wed Sep 5 08:31:34 PDT 2012


Iain Buclaw:

Most of the array allocation cases we are talking about are like:

void main() {
   int[3] a = [1, 2, 3]; // fixed size array
}


That currently produces, with DMD:

__Dmain:
L0:     sub ESP, 010h
         mov EAX, offset FLAT:_D12TypeInfo_xAi6__initZ
         push EBX
         push 0Ch
         push 3
         push EAX
         call near ptr __d_arrayliteralTX
         add ESP, 8
         mov EBX, EAX
         mov dword ptr [EAX], 1
         mov ECX, EBX
         push EBX
         lea EDX, 010h[ESP]
         mov dword ptr 4[EBX], 2
         mov dword ptr 8[EBX], 3
         push EDX
         call near ptr _memcpy
         add ESP, 0Ch
         xor EAX, EAX
         pop EBX
         add ESP, 010h
         ret



There is also the case for dynamic arrays:

void main() {
   int[] a = [1, 2, 3];
   // use a here
}

But this is a harder problem, to leave for later.


> this infact caused many strange SEGV's in quite
> a few of my programs  (most are parsers / interpreters, so 
> things that
> go down *heavy* nested into itself, and it was under these
> circumstances that array literals on the stack would go corrupt 
> in one
> way or another causing *huge* errors in perfectly sound code).

Do you know the cause of such corruptions? maybe they are caused 
by other compiler bugs...

And what to do regarding those exceptions in constructors? :-)

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list