[fpc-pascal] getmem

Luis Fernando Del Aguila Mejía luis3000 at ec-red.com
Tue May 24 17:22:41 CEST 2011


I know that you can use dynamic arrays (array of). Is better.
But this does not understand and confuse me.
Why to create an array of 3 elements (ANSIString) with GetMem, I have to 
put a size of 15 bytes (5*3) and not 12 bytes (4*3).?
The program works with 15 bytes, but do not understand why not work with 
12 bytes.
Thanks.

{$codepage utf8}
Var LCad:^ansiString;
Begin
   getmem(LCad,5*3);  //ansistring is a pointer 4 bytes
   LCad[0]:='01234';
   LCad[1]:='56789';
   LCad[2]:='11111';
   Writeln(LCad[2]);
   freemem(LCad)
End.





More information about the fpc-pascal mailing list