home *** CD-ROM | disk | FTP | other *** search
- /*
- File: MemHook.cpp
-
- Contains: MemoryHook base class implementation
-
- Owned by: Jens Alfke
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <1> 9/13/96 jpa first checked in
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _PLATFMEM_
- #include "PlatfMem.h"
- #endif
-
- #ifndef _MEMHOOK_
- #include "MemHook.h"
- #endif
-
- #ifndef __MEMORY__
- //#include <Memory.h>
- #endif
-
- #ifndef __STDIO__
- //#include <stdio.h>
- #endif
-
-
- //========================================================================================
- // CLASS ODMemoryHook (MM_DEBUG only)
- //========================================================================================
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::ODMemoryHook
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- ODMemoryHook::ODMemoryHook()
- {
- fNextHook = fPreviousHook = this;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::~ODMemoryHook
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- ODMemoryHook::~ODMemoryHook()
- {
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::operator new
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- void* ODMemoryHook::operator new(SIZE_T size, MMHeapLocation src)
- {
- return PlatformAllocateBlock(size, src);
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::operator delete
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- void ODMemoryHook::operator delete(void* ptr)
- {
- PlatformFreeBlock(ptr);
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::GetHeaderSize
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- ODBlockSize ODMemoryHook::GetHeaderSize()
- {
- return 0;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::AboutToAllocate
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- ODBlockSize ODMemoryHook::AboutToAllocate(ODBlockSize size) const
- {
- return size;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::DidAllocate
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- void *ODMemoryHook::DidAllocate(void* blk, ODBlockSize)
- {
- return blk;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::AboutToBlockSize
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- const void *ODMemoryHook::AboutToBlockSize(const void* blk)
- {
- return blk;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::AboutToFree
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- void *ODMemoryHook::AboutToFree(void* blk)
- {
- return blk;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::AboutToRealloc
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- void ODMemoryHook::AboutToRealloc(void* &, ODBlockSize &)
- {
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::DidRealloc
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- void *ODMemoryHook::DidRealloc(void *oldBlk, void *blk, ODBlockSize)
- {
- return blk;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::AboutToReset
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- void ODMemoryHook::AboutToReset()
- {
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::Comment
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- void ODMemoryHook::Comment(const char*)
- {
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // ODMemoryHook::GetType
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- long ODMemoryHook::GetType() const
- {
- return ODMemoryHook::kNoType;
- }
- #endif
-
-
- //========================================================================================
- // CLASS MemoryHookList (MM_DEBUG only)
- //========================================================================================
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // MemoryHookList::MemoryHookList
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- MemoryHookList::MemoryHookList()
- {
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // MemoryHookList::Add
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- void MemoryHookList::Add(ODMemoryHook* aMemoryHook)
- {
- // Add at the fEnd of the list by adding after the last hook in the list.
-
- ODMemoryHook* afterHook = fHead.fPreviousHook;
-
- aMemoryHook->fNextHook = afterHook->fNextHook;
- afterHook->fNextHook->fPreviousHook = aMemoryHook;
- aMemoryHook->fPreviousHook = afterHook;
- afterHook->fNextHook = aMemoryHook;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // MemoryHookList::Remove
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- void MemoryHookList::Remove(ODMemoryHook* aMemoryHook)
- {
- aMemoryHook->fPreviousHook->fNextHook = aMemoryHook->fNextHook;
- aMemoryHook->fNextHook->fPreviousHook = aMemoryHook->fPreviousHook;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // MemoryHookList::First
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- ODMemoryHook* MemoryHookList::First() const
- {
- ODMemoryHook *h = fHead.fNextHook;
- return h != &fHead ? h : NULL;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // MemoryHookList::Next
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- ODMemoryHook* MemoryHookList::After( ODMemoryHook *h ) const
- {
- h = h->fNextHook;
- return h != &fHead ? h : NULL;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // MemoryHookList::Previous
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- ODMemoryHook* MemoryHookList::Before( ODMemoryHook *h ) const
- {
- h = h->fPreviousHook;
- return h != &fHead ? h : NULL;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // MemoryHookList::Last
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- ODMemoryHook* MemoryHookList::Last() const
- {
- ODMemoryHook *h = fHead.fPreviousHook;
- return h != &fHead ? h : NULL;
- }
- #endif
-
- #if MM_DEBUG
- //----------------------------------------------------------------------------------------
- // MemoryHookList::~MemoryHookList
- //----------------------------------------------------------------------------------------
- #pragma segment HeapSeg
-
- MemoryHookList::~MemoryHookList()
- {
- for (ODMemoryHook *hook = First(); hook != NULL; hook = First())
- {
- Remove(hook);
- delete hook;
- }
- }
- #endif
-
-
-