[comp.sys.amiga.programmer] The case of the vanishing memory

mike@zorch.SF-Bay.ORG (Mike Smithwick) (03/12/91)

["Share and enjoy! Share and enjoy! Our plastic girls and plastic boys!"]

I have noticed that when I open a window, then procede to create an event in
 said window (MOUSEMOVE, clicking on a gadget, etc), sometimes I'll 
loose 56 bytes, sometimes.

Ok, so I assume that this is my IntuiMessage (52 bytes + 4 bytes overhead?).
But it is not consistant. It only happens early in the window's life. I can
generate events like crazy, but after a while, the memory loss will stop.

This is very sporadic, and the events that appear to be eating away at 
the memory still get through for me to process and reply to. So its not
like I am ignoring them or anything, but it does seem to have something
to do with how quickly I can get to process them. 

This only happens on my slow (read 68000) machines. On my 020 A1000 and
A3000 it doesn't happen.

So anybody have any idears?

mike 


P.S. Are there any good tools available to check memory fragging?

-- 
"outside of a dog, a book is mans best friend, inside a dog, it's
 too dark to read"-Groucho

Mike Smithwick - ames!zorch!mike

dueker@xenon.arc.nasa.gov (The Code Slinger) (03/13/91)

In article <1991Mar12.070655.1515@zorch.SF-Bay.ORG>, mike@zorch.SF-Bay.ORG (Mike Smithwick) writes...
> 
>I have noticed that when I open a window, then procede to create an event in
> said window (MOUSEMOVE, clicking on a gadget, etc), sometimes I'll 
>loose 56 bytes, sometimes.
> 
>Ok, so I assume that this is my IntuiMessage (52 bytes + 4 bytes overhead?).
>But it is not consistant. It only happens early in the window's life. I can
>generate events like crazy, but after a while, the memory loss will stop.
> 
>This is very sporadic, and the events that appear to be eating away at 
>the memory still get through for me to process and reply to. So its not
>like I am ignoring them or anything, but it does seem to have something
>to do with how quickly I can get to process them. 
> 
>This only happens on my slow (read 68000) machines. On my 020 A1000 and
>A3000 it doesn't happen.
> 
>So anybody have any idears?
> 
>mike 

If'n Ah remember rightly, one of the Sybex books (Peck's?) sez something
about memory being allocated by the system when IntuiMessages are created
and that you should reply to them as fast as you can.

Because, when you reply, the system can reuse the space for another
IntuiMessage.  If'n you don't reply "fast enough", the system will allocate
still more space for messages it needs to send.  This space does not get
deallocated.  (At least not until reboot time, I think)

Chris

------------------------------------------------------------------------
"Ah, Benson, you are so mercifully free of the ravages of intellegence!"
"Oh, thank you, Master!"             - from the movie, TIME BANDITS
------------------------------------------------------------------------
dueker@xenon.arc.nasa.gov        |   Chris Dueker (The Code Slinger)
duke@well.sf.ca.us               |   Mtn. View, CA  (Sillycon Valley!)

peter@cbmvax.commodore.com (Peter Cherna) (03/13/91)

In article <1991Mar12.070655.1515@zorch.SF-Bay.ORG> mike@zorch.SF-Bay.ORG (Mike Smithwick) writes:
>I have noticed that when I open a window, then procede to create an event in
> said window (MOUSEMOVE, clicking on a gadget, etc), sometimes I'll 
>loose 56 bytes, sometimes.
>
>Ok, so I assume that this is my IntuiMessage (52 bytes + 4 bytes overhead?).
>But it is not consistant. It only happens early in the window's life. I can
>generate events like crazy, but after a while, the memory loss will stop.

Intuition allocates messages as needed, though it will always re-use
any messages you've already replied to it.  Those messages get freed
at CloseWindow() time.  Thus, you will appear to lose 56 byte chunks
until a bunch (perhaps a half-dozen or a dozen) are allocated.  After
that, you start to have enough for most circumstances, and only under
heavy load will another be allocated.

Remember, you get it all back when you close the window.

>This only happens on my slow (read 68000) machines. On my 020 A1000 and
>A3000 it doesn't happen.

Intuition's messages are paced to things like the vblank timer.  A faster
CPU allows your application to reply messages faster, keeping the queue
down.

>Mike Smithwick - ames!zorch!mike

     Peter
--
     Peter Cherna, Software Engineer, Commodore-Amiga, Inc.
     {uunet|rutgers}!cbmvax!peter    peter@cbmvax.commodore.com
My opinions do not necessarily represent the opinions of my employer.
"If all you have is a hammer, everything looks like a nail."

markv@kuhub.cc.ukans.edu (03/13/91)

In article <1991Mar12.070655.1515@zorch.SF-Bay.ORG>, mike@zorch.SF-Bay.ORG (Mike Smithwick) writes:
> ["Share and enjoy! Share and enjoy! Our plastic girls and plastic boys!"]
> 
> I have noticed that when I open a window, then procede to create an event in
>  said window (MOUSEMOVE, clicking on a gadget, etc), sometimes I'll 
> loose 56 bytes, sometimes.

But you get it back when you close the window, right?
 
> Ok, so I assume that this is my IntuiMessage (52 bytes + 4 bytes overhead?).
> But it is not consistant. It only happens early in the window's life. I can
> generate events like crazy, but after a while, the memory loss will stop.

Yes, that's correct...
 
> This is very sporadic, and the events that appear to be eating away at 
> the memory still get through for me to process and reply to. So its not
> like I am ignoring them or anything, but it does seem to have something
> to do with how quickly I can get to process them. 

Very good...
 
> This only happens on my slow (read 68000) machines. On my 020 A1000 and
> A3000 it doesn't happen.

Your catching on...
 
> So anybody have any idears?

Yes.  Intuition maintains a list of IntuiMsgs allocated for each IDCMP
port.  When Intuition needs a message, it checks this list.  If one is
available, it uses it, otherwise it turns around and allocates it from
the system, then sends it.  When you finally reply a msg, Intition
does NOT return it to the system, it tacks it onto the free list of
msgs.  When the IDCMP port finally goes away (via CloseWindow() or
ModifyIDCMP(xx,NULL) ), Intuition releases the messages.

So, as long as you fall behind processing the messages, Intuition will
keep grabbing memory from the system for more msgs.  Eventually, the
pool gets to the point where there are enough msgs and it mostly quits
running out.

On faster machines, you program gets more done, and processes the msgs
faster, so the backlog stays a lot shorter.

There is no way to prevent Intuition from doing this, but for most
cases you won't use enough messages to gobble enough memory to cause
problems.  The exception is things like FOLLOWMOUSE which can create
massive amounts msgs very quickly.  

In general the best be is to rip through messages as quickly as
possible.  Dont be afraid to use ModifyIDCMP() to shut off some
messages if your going to go off into space for a while.
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mark Gooderum			Only...		\    Good Cheer !!!
Academic Computing Services	       ///	  \___________________________
University of Kansas		     ///  /|         __    _
Bix:	  mgooderum	      \\\  ///  /__| |\/| | | _   /_\  makes it
Bitnet:   MARKV@UKANVAX		\/\/  /    | |  | | |__| /   \ possible...
Internet: markv@kuhub.cc.ukans.edu
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~