Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uwm.edu!ogicse!zephyr.ens.tek.com!vice!bobb From: bobb@vice.ICO.TEK.COM (Bob Beauchaine) Newsgroups: comp.lang.pascal Subject: Re: need dynamic array on heap Message-ID: <7294@vice.ICO.TEK.COM> Date: 16 Apr 91 23:52:18 GMT References: <1991Apr12.234843.9031@ux1.cso.uiuc.edu> <4816@gumby.Altos.COM> Reply-To: bobb@vice.ICO.TEK.COM (Bob Beauchaine) Organization: Tektronix, Inc., Beaverton, OR. Lines: 41 In article <4816@gumby.Altos.COM> jerry@altos.COM (Jerry Gardner) writes: >In article <1991Apr12.234843.9031@ux1.cso.uiuc.edu> amead@s.psych.uiuc.edu (alan mead) writes: >>I want to put aside a chunk of the heap and then index it by byte like >>an array of byte. I could just declare it as some type like >>'array[1..64000] of byte', but I want to use GetMem so that the array will >>really be dynamic (I don't want to use 64K each time). >> I haven't been following this thread very closely, so this may all have been suggested, but I'm bored... Have you tried a typecast for true dynamic allocation? type byte_buf = array[1..64000] of byte; byte_buf_ptr = ^byte_buf; var buffer : pointer; . . . getmem(buffer,somesize); { Allocate only as many bytes as you need } byte_buf_ptr(buffer)^[2] := somevalue; . . . This allows you to allocate on the fly. It also has it's own caveats. You'd better be damn sure you never write to an array member outside of the actual range of subscripts allocated by your getmem() call, since the compiler can't do range checking on the type cast. Otherwise, I use techniques like this all the time when I don't know what kind of data I'm dealing with until run time. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ Bob Beauchaine bobb@vice.ICO.TEK.COM C: The language that combines the power of assembly language with the flexibility of assembly language.