Path: utzoo!utgpu!watmath!clyde!att!ucbvax!bloom-beacon!apple!well!ewhac From: ewhac@well.UUCP (Leo L. Schwab) Newsgroups: comp.sys.amiga.tech Subject: Re: How to close a device Message-ID: <10120@well.UUCP> Date: 25 Dec 88 09:55:30 GMT References: <587@abo.fi> Reply-To: ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) Organization: Count Pointer-count. Lines: 53 Quote: "I am not interested in trying to compensate for your amazing lack of observation." -- Orac In article <587@abo.fi> vinsci@abo.fi (Leonard Norrgard) writes: > What is the *correct* order to close a device and free buffer memory & >replyports? > > Currently, I'm doing this (where ReadRequest is a struct IOExtSer *): > > if (ReadRequest) { > CloseDevice(ReadRequest); > DeletePort(ReadRequest->IOSer.io_Message.mn_ReplyPort); > FreeMem(ReadRequest, sizeof(*ReadRequest)); ReadRequest = NULL; /* <---- I'd add this */ > } > You may want to add that line in case you plan on re-using the ReadRequest pointer after FreeMem()ing the memory it points to. If you do what I do: opencrud () { if (!(librarybase = OpenLibrary(...))) die (); if (!(ReadRequest = CreateStdReq())) die (); . . . } closecrud () { . . . if (ReadRequest) /* Close it */ if (librarybase) CloseLibrary (librarybase); } ...and plan on calling opencrud()/closecrud() multiple times, then you'll want to set ReadRequest, and all other global pointers, to NULL in your closecrud() routine. This is so that, when you call opencrud() again, all the pointers will start out as NULL, and in case something fails to open, you won't end up trying to close something that you didn't open because the pointer was left non-NULL. Did this make sense? _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ Leo L. Schwab -- The Guy in The Cape INET: well!ewhac@ucbvax.Berkeley.EDU \_ -_ Recumbent Bikes: UUCP: pacbell > !{well,unicom}!ewhac O----^o The Only Way To Fly. hplabs / (pronounced "AE-wack") "Work FOR? I don't work FOR anybody! I'm just having fun." -- The Doctor