home *** CD-ROM | disk | FTP | other *** search
- /*
- File: MemInit.cpp
-
- Contains: CFM initializtion for Memory
-
- Owned by: A. Michael Burbidge
-
- Copyright: © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <16> 6/7/95 jpa Removed old (pre-SLIM) SOM includes.
- [1256901]
- <15> 6/2/95 TJ Included Gestalt.h
- <14> 6/1/95 jpa Restored <12>: Compute total system memory
- at init time [1249619]
- <13> 5/17/95 TJ Backed out changes from previous checkin.
- <11> 1/12/95 jpa Strings.h --> TextUtils.h [1210936]
- <10> 12/5/94 jpa Nuked errant pragma lib_export's. [1195676]
- <9> 10/24/94 jpa Turn off validation
- <8> 10/11/94 NP 1189812: Make Init routine pascal.
- <7> 9/29/94 RA 1189812: Mods for 68K build.
- <6> 9/14/94 jpa Don't include UseRsrcM.h [1186692]
- <5> 9/9/94 jpa Added prototype & commented out initBlkPtr
- to avoid warnings.
- <4> 8/19/94 jpa Call ODInitMemory at library init time
- [1182106]
- <3> 6/30/94 jpa Added InitLibraryResources call.
- <2> 6/23/94 NP Clean up.
- <1> 6/10/94 MB first checked in
- To Do:
- In Progress:
-
- */
-
-
- #ifndef __CODEFRAGMENTS__
- #include <CodeFragments.h>
- #endif
-
- #ifndef _MEMMGR_
- #include "MemMgr.h"
- #endif
-
- #ifndef _MEMDEBG_
- #include "MemDebg.h"
- #endif
-
- #ifndef _MEMMGRPV_
- #include "MemMgrPv.h"
- #endif
-
- #ifndef __GESTALT__
- #include <Gestalt.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __PROCESSES__
- #include <Processes.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef __SOM__
- #include <som.xh>
- #endif
-
-
- MMBoolean gHaveSOM;
-
- size_t gTotalMemory; // Declared in PlatfMem.h
-
-
- static OSErr
- GetProcessName( char name[] )
- {
- name[0] = 0;
-
- ProcessSerialNumber psn;
- psn.highLongOfPSN = 0;
- psn.lowLongOfPSN = kCurrentProcess;
-
- ProcessInfoRec info;
- info.processInfoLength = sizeof(info);
- info.processName = (StringPtr) name;
- info.processAppSpec = kMMNULL;
- OSErr err= GetProcessInformation(&psn,&info);
- if( !err )
- p2cstr((StringPtr)name);
- return err;
- }
-
-
- extern "C" {
- pascal OSErr MemoryCFMInit( CFragInitBlockPtr );
- static void* MMCAllocate( size_t size, size_t n );
- }
-
- static void* MMCAllocate( size_t size, size_t n )
- {
- return MMAllocateClear(n*size);
- }
-
-
- pascal OSErr MemoryCFMInit( CFragInitBlockPtr )
- {
- #if MM_DEBUG
- long result;
- if( Gestalt(gestaltLogicalRAMSize,(long*)&gTotalMemory) != noErr )
- gTotalMemory = 0x80000000; // bogus default value
- if( Gestalt(gestaltVMAttr,&result) == noErr && (result&1) )
- gTotalMemory <<= 1; // Use double logical RAM size if VM on
- // since code fragments get loaded above it
- #endif
-
- // Create a default heap:
- char name[256];
- GetProcessName(name);
- strcat(name," default heap"); // For debugging only so hardcoded string is OK
- MemHeap *heap = MMNewHeap(kMMTempMemory,200*1024L,32*1024L,name);
- if( !heap )
- return memFullErr;
- MMSetDefaultHeap(heap);
-
- gHaveSOM = ((void*)&SOMMalloc != (void*)kUnresolvedCFragSymbolAddress); // Is SOM installed?
-
- if( gHaveSOM ) {
- SOMMalloc = &MMAllocate;
- SOMCalloc = &MMCAllocate;
- SOMRealloc= &MMReallocate;
- SOMFree = &MMFree;
- }
-
- return noErr;
- }
-
-