home *** CD-ROM | disk | FTP | other *** search
- Path: shell1.eznet.net!not-for-mail
- From: armstron@eznet.net (Jon Armstrong)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Referances troubble
- Date: 10 Mar 1996 11:02:45 -0500
- Organization: E-Znet, Incorporated, Rochester, New York (716) 262-2485
- Message-ID: <4huuf5$gih@shell1.eznet.net>
- References: <1266.6624T117T1455@himolde.no> <4gspc8$dj4@oak42.doc.ic.ac.uk>
- NNTP-Posting-Host: shell1.eznet.net
-
- Martin Frost <mdf@doc.ic.ac.uk> wrote:
-
- Hello Martin.
-
- Maybe we can solve your problem as well. Maybe it was a simple typo. :)
-
- >If I understand you correctly, this is the sort of thing you need:
-
- The following is nearly the type of thing the poster wanted, except
- this code also has a bug or two. The function definition/declaration
- is fine, but the way it assigns p1 and p2 is incorrect.
-
- >void func(void **p1, void **p2)
- > {
- > printf("%lx,%lx\n",p1,p2);
-
- Change the following:
-
- > p1 = AllocMem(100,MEMF_CHIP|MEMF_CLEAR);
- > p2 = AllocMem(200,MEMF_ANY);
- > printf("%lx,%lx\n",p1,p2);
-
- to this:
-
- *p1 = AllocMem(100,MEMF_CHIP|MEMF_CLEAR);
- *p2 = AllocMem(200,MEMF_ANY);
- printf("%lx,%lx\n",*p1,*p2);
-
- > }
-
- >int main(void) /* NOTE WELL: main() returns an _int_ */
-
- As it should.
-
- > {
- > void *p1,*p2;
- > printf("%lx,%lx\n",p1,p2);
- > func(&p1,&p2);
- > printf("%lx,%lx\n",p1,p2);
- > if(p1) FreeMem(p1,100);
- > if(p2) FreeMem(p2,200);
- > return(0);
- > }
-
- main looks fine, for the purposes of this matter, at least.
-
- Aside: I prefer to wrap all Amiga specific calls that easily port
- to other environments, like unix. This allows for a much easier time
- testing and porting of course, if you work on both Amiga and non-Amiga
- platforms.
-
- I would rarely call AllocMem() or FreeMem() directly, due to the
- work I'm normally involved with.
-
- A reasonable alternative is to provide a macro or interface
- replacement for those functions on alternate platforms.
-
- #define AllocMem(__size,__type) calloc(1,__size)
- #define FreeMem(__ref,__size) free(__ref)
-
- I usually opt for the standard malloc/calloc/free, or versions
- which provide resource tracking, but I realize the necessity to
- specify things like MEMF_CHIP, from time to time, in the Amiga
- environment.
-
- Just a thought.
-
- Regards... Jon ( #C - Xgc - Please, join us on irc sometime. )
-
- --
- +----------------------------------------------+
- Regards... Jon | Armstrong | LPA Software, Inc. | jma@lpa.com |
- +----------------------------------------------+
-