Delphi xe3 vcl to firemonkey array issue -
when converting vcl firemonkey in delphi, have following issue: in vcl have following array: tcarray=array[1..$04000000] of tcoordinate; - works fine.
however, declaring same array in firemonkey exception stack overflow @ 0x00.. solution far minimize array [1..40000].
why this? solution?
the vcl code follow
unit ptypes; interface uses windows,vcl.graphics,vcl.imaging.jpeg,vcl.imaging.gifimg,system.types; type tcoordinate=packed record x,y:double; end; tcarray=array[1..$04000000] of tcoordinate; tpoly=packed record n:longint; c:tcarray; end;
it called this:
procedure tform12.button2click(sender: tobject); var poly:tpoly; begin poly begin c[1].x:=100; c[1].y:=100; c[2].x:=400; c[2].y:=100; c[3].x:=400; c[3].y:=400; c[4].x:=250; c[4].y:=550; c[5].x:=100; c[5].y:=400; n:=5; end;
this works fine in vcl in fm breaks following error: "project fmtest.exe raised exception class $c00000fd message 'stack overflow @ 0x00af69e7'.
this stack overflow occurs because creating large local variable poly
(of 1.073.741.828 bytes ¡¡¡¡) , stack (the place local variables stored) has limited size.
you can avoid issue redeclarating types in way
pcarray=^tcarray; tcarray=array[1..$04000000] of tcoordinate; tpoly=packed record n:longint; c:pcarray; end;
and use so
var poly : tpoly; //now poly uses 8 bytes of stack space points : integer; begin points:=5; getmem(poly.c,sizeof(tcoordinate)*points); try poly begin c[1].x:=100; c[1].y:=100; c[2].x:=400; c[2].y:=100; c[3].x:=400; c[3].y:=400; c[4].x:=250; c[4].y:=550; c[5].x:=100; c[5].y:=400; n:=points; end; freemem(poly.c); end; end;
Comments
Post a Comment