Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!maverick.ksu.ksu.edu!deimos.cis.ksu.edu!mccall!tp From: tp@mccall.com Newsgroups: comp.lang.fortran Subject: Re: Fun with pointers (long-ish) Message-ID: <124.26e7c6dc@mccall.com> Date: 7 Sep 90 16:12:11 GMT References: <6243@hub.ucsb.edu> Distribution: comp Organization: The McCall Pattern Co., Manhattan, KS, USA Lines: 34 Alternate way to do it below. This is just as gross, so don't flame about it. I inherited code similar to the original posting and had to port it. It was too big to rewrite. My main objection was the fixed size array. Too small, and you crash, too big and you waste mucho memory. Using the same assumption (subscript checking can be defeated), if you have a memory allocator (lib$get_vm on VMS, malloc on unix), just use it. What you do is declare blank common like so: COMMON // IMEM(1) Put that in the allocator and all routines that use dynamic memory (i.e. with an include file). In your allocator, allocate a block of memory and then determine what subscript for array imem is needed to access the allocated memory (that's the magic part, but can be solved easily with an assembler or C subroutine if your fortran doesn't have the appropriate extentions). Return that value. Your code then accesses dynamic memory by accessing IMEM(ADDR+OFFSET). Note that you can define "structures" by declaring the imem array larger and equivalencing things to it. Then you can use the same offset for all the members of the structure to get to all the various locations (be sure to increment it properly!). Just to catch errors with this setup, I actually have the IMEM array itself set up as read-only memory (on VMS, don't know how you'd do that on unix) so that using a "reasonable" subscript with it will fail. It's a major hack, but so is what he proposed, and this at least can save some statically allocated memory. -- Terry Poot The McCall Pattern Company (uucp: ...!rutgers!ksuvax1!mccall!tp) 615 McCall Road (800)255-2762, in KS (913)776-4041 Manhattan, KS 66502, USA