Pointers to pointers 
Author Message
 Pointers to pointers

Quote:

>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.

* http://www.*-*-*.com/ ~anders



Wed, 18 Jun 1902 08:00:00 GMT  
 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
--



Wed, 18 Jun 1902 08:00:00 GMT  
 Pointers to pointers



Quote:

>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.

--

  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)



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. pointers, pointers, pointers...

2. Pointers Pointers Pointers

3. Beginner needs some pointers with pointers!

4. POINTERS POINTERS...

5. Declaring Far pointers in Pascal, i.e. pointers that point to mem outside of stack!

6. Pointer Arithmetic in TP7.0?

7. test being initialised of pointers and objects

8. pointer to function

9. Turbo Pascal Frequently Asked Questions, a monthly pointer

10. question: BP pointer NEW

11. need pointer to information please

12. FAQ Pointer?

 

 
Powered by phpBB® Forum Software