Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ukma!husc6!bloom-beacon!athena.mit.edu!lwvanels From: lwvanels@athena.mit.edu (Lucien Van Elsen) Newsgroups: comp.sys.mac.programmer Subject: Re: Allocating arrays? Message-ID: <9127@bloom-beacon.MIT.EDU> Date: 6 Feb 89 17:34:55 GMT References: <867@fornax.UUCP> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: lwvanels@athena.mit.edu (Lucien Van Elsen) Distribution: na Organization: Massachusetts Institute of Technology Lines: 26 In article <867@fornax.UUCP> you write: >Here's a simple question I'd appreciate some advice on. I'm using LightSpeed >Pascal 2.0 (great product, by the way, Rich), and I want to dynamically >allocate arrays of structured types, with the number of elements in the >arraynot known until the array is actually allocated. I solved a similar problem by declaring a type that's an array as large as you might ever possiblly want it, and then creating a handle in the program that's only as large as you need. I.E. type comparray : array[1..maxnum] of complextype; compptr : ^comparray; comphan : ^compptr; myhandle := comphan(Newhandle(sizeof(wanted*sizeof(complextype)))); (where wanted is the desired number of elements in the array) You have to take care that you never reference an index larger than the number you have allocated- there's nothing to stop you from going past the end of the handle you have allocated. However, it is possible to dynamically grow/shrink the array while the program is running using SetHandleSize(myhandle,newnum*sizeof(complextype)). Hope this helps! Lucien Van Elsen Internet:lwvanels@athena.mit.edu or lve@wheaties.ai.mit.edu UUCP: ...!mit-eddie!mit-athena!lwvanels