CompuServe Thread

#Alloc'd vs. Free?

15 messages in this thread
#28960From: SyndesisOct 8, 1992 12:53 PM
It's true that the Amiga keeps only a list of free memory, and not a list of allcoated pieces, right? Can anyone recall the release of C code to set-function the AllocMem() call to watch allocations as they are made, or something that makes and watches a list of allocations instead of the list of free memory? Does MungWall do this, inside?
#28974From: Jim Nangano/SYSOPOct 8, 1992 4:44 PM
John, Not quite sure what you're looking for. Mungwall does hook both AllocMem() and FreeMem() calls – it wraps both ends of the allocation with "cookies", which it checks when the memory is freed (to detect overruns). It also has an option to log all allocations/frees to the serial port (do you remember the "ancient" debugging tool called Snoop?). This log can then be "collapsed" with a utility called SnoopStrip, to help identify unfreed allocations. This "snoop" feature will generate a lot of data for most applications, which means that they'll run extremely slow when it's running. You really do need a second system connected to capture the output for post-processing. The latest developer release of Mungwall (it's a "beta" version so it's not distributable) has a couple of other features as well. Hope this helps… – BobR (Motorola Inside!)
#29006From: SyndesisOct 8, 1992 10:14 PM
I'd like to write my own program that set-functions AllocMem(). That's all.
#29050From: Vic WagnerOct 9, 1992 3:33 PM
John, you need the docs on SetFunction()?? exec.library/SetFunction NAME SetFunction — change a function vector in a library SYNOPSIS oldFunc = SetFunction(library, funcOffset, funcEntry) D0 A1 A0.W D0 APTR SetFunction(struct Library *,LONG,APTR); FUNCTION SetFunction is a functional way of changing where vectors in a library point. They are changed in such a way that the checksumming process will never falsely declare a library to be invalid. WARNING If you use SetFunction on a function that can be called from interrupts, you are obligated to provide your own arbitration. NOTE SetFunction cannot be used on non-standard libraries like pre-V36 dos.library. Here you must manually Forbid(), preserve all 6 original bytes, set the new vector, SumLibrary(), then Permit(). INPUTS library – a pointer to the library to be changed funcOffset – the offset of the function to be replaced funcEntry – pointer to new function RESULTS oldFunc – pointer to the old function that was just replaced or do you need the: 3.HEARTOFGOLD.ZAPHOD:2.0_Misc/AutoDocs> lvo exec AllocMem exec.library LVO $ff3a -198 AllocMem() AllocMem(byteSize,requirements)(d0/d1)
#29053From: SyndesisOct 9, 1992 3:48 PM
No, I had them, thanks… I'd just never done this from C before, so I was hoping for an example to re-craft.
#29144From: Joanne DowOct 12, 1992 2:26 AM
Um – AllocMem is perhaps one of the more dangerous calls to SetFunction(). Be *ABSOLUTELY* certain you *MUST* do this before attempting it. {@_@}
#29148From: Vic WagnerOct 12, 1992 4:22 AM
Joanne, 'Tis not I who wishes to SetFunction() it. 'Tis John Foust.
#29049From: Vic WagnerOct 9, 1992 3:33 PM
John, changing all the calls to AllocRemember shouldn't be THAT hard (or do you have too much code to change?). If you SetFunction AllocMem() you are watching _everyone's_ allocations, not just yours. Mungwall indeed watches allocation and frees, but I don't think it logs anywhere. Maybe you want snoop and snoopstrip?? Here's a list of what's in my debug/memory directory (I think most of this came from C=): 3.HEARTOFGOLD.ZAPHOD:2.0_Misc/debug> dir memory drip eatmem flush frags memlist memmon owner owner.doc owner.doc,v peek poke settaskname snoop snoopstrip sparemem I'm not sure I remember what all of these do (or any of them for that matter).
#29072From: Jim Nangano/SYSOPOct 9, 1992 11:32 PM
Vic, Mungwall indeed does have a "snoop" option, that is identical in function to the original snoop. The output is strippable via snoopstrip. Very useful for locating memory leaks. Hope this helps…. – BobR
#29062From: Steve GoddardOct 9, 1992 6:15 PM
John, I use the Memwatch library to do what you want. The version I have is on FF240 (way back), comes with source, and was written by the software distillery. It keeps track of all allocmem/malloc/freemem/free, and does whacky things like report blocks that aren't freed, and blocks that are used after they are freed. It's very nice, IMHO, as it even reports the line of code the AllocMem was done. Sadly, it doesn't cope with AllocVec/FreeVec, but it shouldn't be too tricky to mod the source. Steve the G (Steve Goddard 100014,674) [BEDFORDSHIRE, UK]
#29380From: John Toebes/SYSOPOct 19, 1992 9:27 PM
You REALLY want to do this? It sounds like you might want to look at some to the Bill Hawes magic to setfunction only for specific tasks. Talk about a tricky one to setfunction.
#29397From: SyndesisOct 20, 1992 7:13 AM
Why is setfunctioning AllocMem any more dangerous than other functions? I realize it's crucial to a lot of operations, :-), but other than that?
#29424From: John Toebes/SYSOPOct 20, 1992 7:03 PM
Sure, and next you are going to ask me why things blow up when you put a match to a stick of dynamite 🙂 😉 :-)…. Seriously, everything in the system is built around allocating memory. I just see shades of accidental recursion in a setfunction for AllocMem more easily than any other system call (let's see, I need a block of memory to track all these calls…). It is just one of those functions (like Signal, Wait) which take a little more thought than the others.
#29432From: SyndesisOct 20, 1992 10:16 PM
If I do all my allocations before I do the set-function, where's the risk? When else would an allocation take place? I don't think I want to do anything – I just want to stop when I see a certain allocation.
#29512From: John Toebes/SYSOPOct 22, 1992 9:44 PM
It shouldn't be a problem IF you allocate everything first. Note however that once you setfunction() it, it is never really safe to remove the setfunction. There has been a lot of discussion of this over the years.