GC vs. Manual Memory Management Real World Comparison

Iain Buclaw ibuclaw at ubuntu.com
Wed Sep 5 08:48:04 PDT 2012


On 5 September 2012 16:31, bearophile <bearophileHUGS at lycos.com> wrote:
> 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? :-)
>

I think it was mostly due to that you can't tell the difference
between array literals that are to be assigned to either dynamic or
static arrays (as far as I can tell).   I do believe that the issues
surrounded dynamic arrays causing SEGVs, and not static  (I don't
recall ever needing the use of a static array :-).


Regards
-- 
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';


More information about the Digitalmars-d-announce mailing list