Board index » delphi » Pointers to pointers

Pointers to pointers

Quote
John Matthews <j...@johnmatthews.demon.co.uk> wrote:
>All my arrays are on the heap, and each element is a variable which points
>to the data  like so.....   Name[index]^.address     but if I have 10,000
>names that will take up 40,000 bytes.   How do I TYPE the whole array on
>the heap with just a 4 byte pointer referencing the base of the array.  And
>when I have done that, how do I use the code in practice?

   Type  
        OneName = ^String;   { this is pointer to actual data }
        NameList = array [0..10000] of OneName;  { list of pointers }
   Var
        Name : ^NameList;  { pointer to name list }
        I : Integer;

   Begin
        { assume you already initialized all data }
        I:=0;
        While  Name^[I]<>Nil do
           Begin  Writeln(Name^[i]^ ); Inc(I);  End;
   End.
* Anders LEE   and...@hk.super.net
* http://www.hk.super.net/~anders

 

Re:Pointers to pointers


Hi!

All my arrays are on the heap, and each element is a variable which points
to the data  like so.....   Name[index]^.address     but if I have 10,000
names that will take up 40,000 bytes.   How do I TYPE the whole array on
the heap with just a 4 byte pointer referencing the base of the array.  And
when I have done that, how do I use the code in practice?

RGDS, John
--
J...@johnmatthews.demon.co.uk

Re:Pointers to pointers


In article <v3tmxGABVhL0E...@johnmatthews.demon.co.uk> of Sun, 28 Sep
1997 09:28:49 in comp.lang.pascal.borland, John Matthews <john@johnmatth

Quote
ews.demon.co.uk> wrote:

>Hi!

>All my arrays are on the heap, and each element is a variable which points
>to the data  like so.....   Name[index]^.address     but if I have 10,000
>names that will take up 40,000 bytes.   How do I TYPE the whole array on
>the heap with just a 4 byte pointer referencing the base of the array.  And
>when I have done that, how do I use the code in practice?

The first section of  http://www.merlyn.demon.co.uk/pas-bptp.htm#BigData
shows it.

You probably have
        var Name : array [0..9999] of PXdotAddress ;
        ...
        for J := 0 to 9999 do New(Name[J]) ;
        ...
        Name[Index]^.address
you need
        type TName = array [0..9999] of PXdotAddress ;
        PName = ^TName ;
        var NamePtr : PName ;
        ...
        New(NamePtr) ;
        for J := 0 to 9999 do New(NamePtr^[J]) ;
        ...
        NamePtr^[Index]^.address

or suchlike.

--
John Stockton, Surrey, UK.    j...@merlyn.demon.co.uk    Turnpike v1.12    MIME.
  Web URL: http://www.merlyn.demon.co.uk/ - FAQqish topics, acronyms and links.
  Correct 4-line sig separator is as above, a line comprising "-- " (SoRFC1036)
  Before a reply, quote with ">" / "> ", known to good news readers (SoRFC1036)

Other Threads