Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!bloom-beacon!oberon!cit-vax!elroy!ames!ucbcad!ucbvax!CORY.BERKELEY.EDU!dillon From: dillon@CORY.BERKELEY.EDU.UUCP Newsgroups: comp.sys.amiga Subject: Re: SetWindowTitles and memory allocation Message-ID: <8710030336.AA22313@cory.Berkeley.EDU> Date: Fri, 2-Oct-87 23:36:05 EDT Article-I.D.: cory.8710030336.AA22313 Posted: Fri Oct 2 23:36:05 1987 Date-Received: Sun, 4-Oct-87 02:32:21 EDT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 41 > I have a question about SetWindowTitles and memory allocation. > Suppose you have a window with a title "Shoobeedoo". > Let's call SetWindowTitles(window,"Wapdoowap",0). > What happens to the string "Shoobeedoo" ??? SetWindowTitles() does not duplicate the string. Rather, it uses the string you pass to it. Since no assumptions on the string you pass it can be made, no memory allocation or freeing is done. So if you allocate the string you give to SetWindowTitles() you must deallocate after you close the window (or make a call with a different string to SetWindowTitles()). Otherwise you generally don't have to worry about it. >2) It's reasonnable to think that the pointer to the window's titles > string will be updated. What happens if the string "Wapdoowap" is > somewhere in the stack, and then after some other code, this > part of the stack is destroyed ? > Does SetWindowTitles() copy the string for its own use ?? As SetWindowTitles() does not copy the string, you must be sure to keep that string around while it is being used in SetWindowTitles(). If you modify the string, you want to make a call to SetWindowTitles() to ensure it is updated properly. Note that you should be careful about modifying the string. If Intuition decides to look at it while you're in the middle of modifying it... specifically if you've overwritten the end of string mark (0)! >More generally, do we have such functions that use memory they can't >deallocate anyway ? Any library call that requires a string will either (A) use the string pointer provided or (B) copy it and handle the copy internally. In the case of (A), it will either (1) use the string and then discard it or (2) use the string and expect the string to stay valid after returning. Open() would use the filename then not care what you use that string for after it returns. SetWindowTitles() as we know keeps the pointer around. -Matt