Path: ns-mx!hobbes.physics.uiowa.edu!zaphod.mps.ohio-state.edu!mips!mips!munnari.oz.au!comp.vuw.ac.nz!actrix!David.Empson From: David.Empson@bbs.actrix.gen.nz Newsgroups: comp.sys.apple2 Subject: Re: HELP! Message-ID: <1992Feb27.132225.38@actrix.gen.nz> Date: 27 Feb 92 13:22:25 GMT References: Sender: David.Empson@actrix.gen.nz (David Empson) Organization: Actrix Information Exchange Lines: 52 In article qd@pro-calgary.cts.com (Quinn Dunki) writes: > I have a question for any C programmers out there. Could someone please > tell me why this code fragment doesn't work? > [fragment removed] If your 'zero' array has been declared inside a function, the C compiler will try to allocate it on the stack. The array is 50800 bytes long. You have 8000 bytes of stack space available. Therefore, the array will be starting at a very strange place in bank zero, and when you try to clear it, you will overwrite system variables, parts of GS/OS, possibly I/O space, and other programs' direct page areas. There are two possible solutions to this: either declare the array as 'static', so it will be allocated in the data segment for ORCA/C's small model (which can contain up to 64k), or the array segment for ORCA/C's large model or for APW C (which is limited only by available memory). The same effect can be achieved by moving the array definition outside of the function. This is necessary if you want other functions to access the array. If the array _has_ been declared outside a function, then I don't know what the problem is. One incidental problem: your write loop is writing out the first array element 25400 times. You should be using: fwrite(&zero[c], 2, 1, k); Two other points: 1. To clear a large area of memory, you can use the memset() function, i.e. memset(&zero[0], 0, sizeof(zero)); Don't forget to include . 2. You can replace the file write loop with a single call to fwrite: fwrite(zero, 2, 25400, k); It seems a little extravagant to define a 25400 element array - you could use a much smaller array, and write it multiple times (e.g. 254 bytes, written 100 times). -- David Empson Internet: David.Empson@bbs.actrix.gen.nz EMPSON_D@kosmos.wcc.govt.nz Snail mail: P.O. Box 27-103, Wellington, New Zealand Path: ns-mx!uunet!vuse.vanderbilt.edu!benson From: benson@vuse.vanderbilt.edu (Paul BaJa Benson) Newsgroups: comp.sys.apple2 Subject: Re: TML Pascal II... Message-ID: <1992Mar3.065548.17178@vuse.vanderbilt.edu> Date: 3 Mar 92 06:55:48 GMT References: <1992Mar3.021749.11353@nuscc.nus.sg> Sender: news@vuse.vanderbilt.edu Organization: Vanderbilt Univ., Engineering (SERG), Nashvegas, TN Lines: 27 Nntp-Posting-Host: space0 In article <1992Mar3.021749.11353@nuscc.nus.sg> ltchean@iss.nus.sg (lim thye chean) writes: ~So without this operator, the new algorithm is sooooo much slower. Or somebody ~else can provide me with a short algorithm that can handle Power(x, y: integer) ~: longInt efficiently? First off, how are you doing it now? One of the quickest (line wise or with an FPE) is for x^y: answer := exp(y*ln(x)); Another method (for C and assembly people, don't know how you'd do it in Pascal off hand): answer = 1; /* a longint */ for (lcv = 0; y && (lcv < num_bits_for_integer); lcv++, x = x*x, y >>= 1) if (y & 0x01) answer *= x; This is O(logn), so it is fairly quick. If you don't know C, && is logical AND, lcv++ means lcv = lcv+1, y >>= 1 means right shift y one bit, answer *= x means answer = answer*x, and y & 0x01 does a boolean AND with y and 1 (checks lsb). ~ Lim Thye Chean: Lim is my surname. My name is Thye Chean. -- Paul 'BaJa' Benson Vanderbilt University - Space Electronics Research Group GEnie: P.Benson1 Net: benson@vuse.vanderbilt.edu