Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwvax!umn-d-ub!nic.MR.NET!srcsip!coltrane!carpent From: carpent@coltrane.SRC.Honeywell.COM (Todd Carpenter) Newsgroups: comp.sys.amiga Subject: C help (Long) : Dynamic Allocation and Globals Message-ID: <23129@srcsip.UUCP> Date: 6 Jun 89 02:38:47 GMT Sender: news@src.honeywell.COM Lines: 60 Hello, oh great and mighty C wizards of the net! I beg of thee guidance... Okay, these are not *pure* amiga questions. But I am writing (what I think will a be useful and impressive) program on my amiga, and have encountered a few stumbling blocks. Please *email* me replies. 1) Speed is the prime consideration. This will *not* be a small program by any means, but it has to be fast. 2) But, it is also big. The data arrays for small systems are over 256K. and I have multiple arrays. SO I can't waste too much space. Question 1) People have been talking about residentable programs, and generally good (for the Amiga) programming techniques. One of the points is to avoid global variables. But I cannot think of any way to avoid global variables, without suffering a hit in performance. unsigned moo(param1,param2,iteration) unsigned param1,param2 { return( (param1 - param2 < 0) || (iteration & MASK == MASK) ) } Now, moo is one of many functions which return true or false. Which function is chosen (and initialized) at the begining. A pointer to moo is returned (so I oont have to go through a SWITCH statement). So I want a generic interface to those functions, and the above interface *should* be sufficient. However, some of the routines require a few items (MASK in the above) initialized by the user. These values are set once, at the beginning, or may actually change through events other than that within moo. So, how do I get MASK to moo without using globals? I *don't* want to pass it in (since it would be a non uniform interface), and I don't want to have a test to see if it is an initialization phase. related - what about static variables inside moo? Will they cause troubles? Question 2: This is another embarrassing one. I can't afford to waste space, so I'd like to declare my arrays to be only as large as necessary. These two dimensional arrays are indexed very frequenty. How do I allocated from the heap the following: unsigned short MOO [Xdimension] [YDimension]; Where X and Y are determined at runtime (256x256 would be considered reasonable values)? if I pass MOO to a procedure, how do I reference element MOO[x][y]? Do I start building pointer offsets and other ickies, or are there nice ways? Thanks in advance! Todd P. Carpenter Honeywell Systems and Research Center voice: (612)782-7229 paper: 3660 Technology Drive, Minneapolis, MN 55418 UUCP: carpent@srcsip.uucp bang-style: {umn-cs,ems,bthpyd}!srcsip!carpent Internet: carpent@src.honeywell.com or carpent@altura.honeywell.com