Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!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: <7309@vice.ICO.TEK.COM> Date: 18 Apr 91 16:25:02 GMT References: <1991Apr12.234843.9031@ux1.cso.uiuc.edu> <4816@gumby.Altos.COM> <7294@vice.ICO.TEK.COM> <91107.174405SPRAGGEJ@QUCDN.QueensU.CA> Reply-To: bobb@vice.ICO.TEK.COM (Bob Beauchaine) Organization: Tektronix, Inc., Beaverton, OR. Lines: 35 In article <91107.174405SPRAGGEJ@QUCDN.QueensU.CA> SPRAGGEJ@QUCDN.QueensU.CA (John G. Spragge) writes: >In article <7294@vice.ICO.TEK.COM>, bobb@vice.ICO.TEK.COM (Bob Beauchaine) says: >> >> 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; > >Actually, since GETMEM takes ANY pointer type, you don't need >the typecast. You don't have to allocate enough memory for the >structure you're loading; you just have to be sure your code >will manage dynamic structures correctly. > You most certainly do need the typecast. Notice the getmem call does not use the typecast; it's the reference to the pointer as a pointer to an array of bytes that requires the typecast. Guess you weren't reading too close :). As I said, I use this method frequently. You don't get a free lunch; bypassing Pascal's strong type checking takes a little more work. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ Bob Beauchaine bobb@vice.ICO.TEK.COM C: The language that combines the power of assembly language with the flexibility of assembly language.