Thread View: comp.sys.next.programmer
3 messages
3 total messages
Started by Shawn Willden
Tue, 28 Jul 1992 21:44
NeXTmille and swapping
Author: Shawn Willden
Date: Tue, 28 Jul 1992 21:44
Date: Tue, 28 Jul 1992 21:44
67 lines
4367 bytes
4367 bytes
Hi all, As a newcomer to NeXT programming and a poor student that can't afford NeXT DevCamp, I decided that a good way to learn about NeXT programming was to examine/fix some already-written programs. One of my favorite PD games is NeXTmille-2.0 written by Dennis Glatting of Threaded Technologies, but it has a problem. If you've ever played it, you know that after a few hands the game becomes unplayable because of intense swapping. The swapfile grows and grows and eventually response time gets so bad that you must give up, kill the game and start over. I undertook to correct this flaw. If you already know what this particular game's problem is, great, if not, either hit 'n' now or settle back for a discussion of my attempts to discover the bug, then offer any ideas you may have. The obvious first guess is that Dennis created objects in the process of play that he did not later destroy. Likely candidates were the cards. My first guess was that he created a new deck for every hand (though after looking through his code for a while I decided he wasn't so naive as that). A little investigation revealed that the cards were only created once, at the beginning of the game, and persisted until the game's end (precisely the way I would have done it, though I probably would have explicitly freed them at the end, just out of habit). This fact was also verified by tossing a few printf's into the init methods of the various card classes and watching the console output of a game. My next ploy was to find all uses of dynamic memory allocation in the program through the simple expedient of Edit `grep -l alloc *.[chm]` in the source directory and then looking to see that the objects were free'd somewhere. Well, Dennis never did bother to free the cards and a couple of other items but that's okay because they were only created once and of course die with the termination of the program. I was able to verify that all other instances of explicit dynamic allocation were either correctly free'd or the memory was allocated with alloca() which should free the memory upon exit from the current function/method. After poring over the code for many additional hours, searching for illumination, I decided to use my weapon of last resort, yes, I decided to RTFM. I read all about memory allocation and zones and such and finally I discovered MallocDebug. "Hah!" I thought, "Here's the answer to all of my problems." Unfortunately, MallocDebug reported few leaks and informed me that most of the new memory being allocated by the program was coming from the ObjC zone, accessed by objc_malloc(). And worst of all, MallocDebug told me that between the time the game had completed startup and the time the game became unplayable only ~40K had been allocated. In fact, the total allocated memory was less than 160K! This did not go far towards explaining the ~10Mb increase in the size of my swapfile or the continual swapping. Even assuming that all the data was horribly fragmented across many pages I couldn't see a way to justify that much swapping. After continued hours of reading everything I though might be related, I gradually began to admit to myself that there remained only three possibilities that made any sense: 1) MallocDebug was wrong and I was missing something that a little more work with the code could uncover. 2) Something was wrong with Mach's swapping algorithm. 3) I was REALLY missing some vital information and if it was in the on-line manuals I couldn't find it. So, that's that. I declared myself officially stumped and decided to abase myself before the Gods of NeXT Programming via the net and beg for some scrap of guidance. Maybe Dennis is here? Any ideas? Shawn Willden swillden@cc.weber.edu
Re: NeXTmille and swapping
Author: John Soward
Date: Wed, 29 Jul 1992 12:45
Date: Wed, 29 Jul 1992 12:45
22 lines
1481 bytes
1481 bytes
Shawn Willden writes
-> Hi all,
->
->
-> 1) MallocDebug was wrong and I was missing something that
-> a little more work with the code could uncover.
-> 2) Something was wrong with Mach's swapping algorithm.
-> 3) I was REALLY missing some vital information and if it
-> was in the on-line manuals I couldn't find it.
Easy thing to do is use "ps" from terminal and *see* what processes seem to
have a large chunck of memory allocated to them...I haven't looked at the code
at all, but my guess would be that the WindowServer will be the culprit. And
that it arises from many Views/Windows/etc that are being allocated and perhaps
not freed/re-used.
Good luck,
--
________________________________________________________________________
/ 'The midnight sun will burn you up" -The Cure, Piggy in the Mirror /
/ soward@ms.uky.edu | soward@slow.inslab.uky.edu (NeXT Mail) /
/_______________________________________________________________________/
Re: NeXTmille and swapping
Author: Don Yacktman
Date: Wed, 29 Jul 1992 14:43
Date: Wed, 29 Jul 1992 14:43
38 lines
2356 bytes
2356 bytes
In article <1992Jul29.124549.8044@ms.uky.edu>, soward@slow.inslab.uky.edu (John Soward) writes: >Shawn Willden writes >-> Hi all, >-> >-> >-> 1) MallocDebug was wrong and I was missing something that >-> a little more work with the code could uncover. >-> 2) Something was wrong with Mach's swapping algorithm. >-> 3) I was REALLY missing some vital information and if it >-> was in the on-line manuals I couldn't find it. > >Easy thing to do is use "ps" from terminal and *see* what processes seem to >have a large chunck of memory allocated to them...I haven't looked at the code >at all, but my guess would be that the WindowServer will be the culprit. And >that it arises from many Views/Windows/etc that are being allocated and perhaps >not freed/re-used. > >Good luck, >-- > ________________________________________________________________________ > / 'The midnight sun will burn you up" -The Cure, Piggy in the Mirror / > / soward@ms.uky.edu | soward@slow.inslab.uky.edu (NeXT Mail) / > /_______________________________________________________________________/ Yes, it _is_ the window server. Run it with -NXShowAllWindows. Every time you drag a card, etc, an offscreen buffer for the card is created, and the card is drawn in it, but the buffer is never freed. Thus, the window server grows and grows and grows. :( I haven't had time to fix this problem myself, but I know that that is the problem. If anyone _does_ fix it, let me know before you post it to sonata, because I _have_ made a colorized version, and would like to include the color support in the fixed version. If you wait long enough, I'll fix it myself anyway. :) (The colorized version required new .tiffs and a change to the pswrap that draws the stoplights; simple changes, really.) Later, -Don Yacktman
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads