Path: utzoo!utgpu!news-server.csri.toronto.edu!qucdn!spraggej Organization: Queen's University at Kingston Date: Friday, 19 Apr 1991 23:49:43 EDT From: John G. Spragge Message-ID: <91109.234943SPRAGGEJ@QUCDN.QueensU.CA> Newsgroups: comp.lang.pascal Subject: Re: need dynamic array on heap References: <1991Apr12.234843.9031@ux1.cso.uiuc.edu> <4816@gumby.Altos.COM> <7294@vice.ICO.TEK.COM> <91107.174405SPRAGGEJ@QUCDN.QueensU.CA> <7309@vice.ICO.TEK.COM> In article <7309@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. The way I do it is: TYPE pflexb = ^flexb; flexb = ARRAY [1 .. 64000] OF CHAR; VAR fb : pflexb; c : INTEGER; BEGIN GETMEM (fb, 2000); FOR c := 1 TO 2000 DO fb [c] := 'm'; END. I think yo'll find that works well enough, withot requiring a typecast. To anyone who thoght I was saying yo don't need a typecast the dereference a generic pointer, I apologize. disclaimer: Queen's University supplies me with computer services, not my opinions. John G. Spragge