On Wed, 11 Jul 2001, Prof. A Olowofoyeku (The African Chief) wrote:
On 10 Jul 2001, at 18:24, Adam Naumowicz wrote:
Hello,
I have a basic question concerning strings and array memory representation in GPC. To my amusement I noticed that in the following program the string assigned to an array element cannot be then restored from the array itself. So probably an array of strings is not represented in memory just like an array of simple type, and cannot (?) be simply getmem-ed ?
program test; type NameStr=String[8]; shortarray=array[1..3] of NameStr;
var n:NameStr; a:^shortarray; i:integer;
begin getmem(a,3*sizeof(NameStr));
This is your problem. Use 'New' instead of 'getmem' - i.e., New (a, 3 * sizeof (NameStr)); or New (a, sizeof (shortarray)); or better still, just "New (a);"
In fact SizeOf(shortarray) is not what I really want. This example comes from a very old piece of code and of course it should be changed to a collection but it is not the point. I would like to have a pointer to an array that is large enough (up to some limit) like shortarray=array[1..30000] of NameStr; but allocate only some part of it that is really required at the moment. Regards, Adam Naumowicz
-------------------------------------- WWW: http://math.uwb.edu.pl/~adamn/ --------------------------------------