Dynamic arrays... 
Author Message
 Dynamic arrays...

OK folkz... how are dynamic arrays done in TP 7.0?



Mon, 28 Feb 2000 03:00:00 GMT  
 Dynamic arrays...

Quote:

> OK folkz... how are dynamic arrays done in TP 7.0?

{$R-}

type
    myType = record
               junk: string[8];
               more_junk: longint;
               trash: word;
             end;            
    MegaArray = array[0..0] of myType;
    MegaArrayPtr = ^MegaArray;
var
   myMegaArray: MegaArrayPtr;
   NumEntries: word;
   i: integer;

begin
     NumEntries:= sizeof(myType) div 65535;
     getmem(myMegaArray,sizeof(myType)*NumEntries);

     { use the array }
     for i:= 0 to NumEntries - 1 do
        with myMegaArray^ do
        begin
           junk:= "Nothing";
           more_junk:= 1000;
           trash:= i;
        end;    

     { abuse the array }
     ...

     { free the array }

     freemem(myMegaArray,sizeof(myType)*NumEntries);
end.

Thats one way...

--
- Asbj?rn


http://home.sol.no/~bheid/



Mon, 28 Feb 2000 03:00:00 GMT  
 Dynamic arrays...



Quote:
> OK folkz... how are dynamic arrays done in TP 7.0?

My Way is to use Dynamic Linked Lists - Pascal or C or BASIC/V
I prefer the linked list system as it is easier to manipulate...
Otherwise the easiest way is to declare the largest possible
array, but only allocate as much as you need on the heap, e.g.

 Type
  TBigArray[0..65531] of Byte;

 procedure could say:

 var
  myarr : ^TBigArray;

  MyArr:=GetMem(150)

--
Daniel Silverstone (Usually ;)

Look at the farstar Homepages on:
 http://www.farstar.demon.co.uk/

Try out Daniel's TPascal Page & Delphi 2.0 bits at
 http://www.farstar.demon.co.uk/Pascal/index.htm

Mail me & give comments (I know it's sparse ;)



Tue, 29 Feb 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. dynamic array

2. Dynamic array in database

3. How to store dynamic array to memofield?

4. Dynamic Array puzzle

5. How to declare dynamic array in fpc ??

6. dynamic arrays

7. Memory access; relative position (dynamic array)

8. Heap error while allocating dynamic array in protected.

9. How do you do a dynamic array in oascal

10. Dynamic arrays?????

11. Question: Dynamic arrays in Turbo Pascal

12. dynamic arrays

 

 
Powered by phpBB® Forum Software