fixmem.cpp File Reference

(r1785/r1282)

#include "camtypes.h"
#include <malloc.h>
#include "tunemem.h"

Go to the source code of this file.

Defines

#define checksize(x)   FALSE
#define CheckMagic(p, k)   (p)
#define StoreMagic(p, s, f, l)   (p)
#define LinkMagic(p)
#define MAGIC_EXTRA   0

Functions

LPVOID RetailCCMalloc (UINT32 Size)
 Like malloc but does not throw exceptions.
LPVOID RetailCCRealloc (LPVOID Buf, UINT32 Size)
 Change size of memory block, similar to realloc but does not throw exceptions.
size_t RetailCCGetBlockSize (LPVOID Block)
 Finds out how big a block of ram someone asked for when they called CCMalloc.
void CCFree (LPVOID Buf)
 Like malloc but does not throw exceptions. Change size of memory block, similar to realloc but does not throw exceptions. Like free.
TunedMemoryGetTunedMemManager ()
 Finds the Tuned Memory manager so that people that need to know get ask it for memory etc.

Variables

static TunedMemory TheTunedMemoryManager


Define Documentation

#define CheckMagic p,
 )     (p)
 

Definition at line 545 of file fixmem.cpp.

#define checksize  )     FALSE
 

Definition at line 133 of file fixmem.cpp.

#define LinkMagic p   ) 
 

Definition at line 547 of file fixmem.cpp.

#define MAGIC_EXTRA   0
 

Definition at line 548 of file fixmem.cpp.

#define StoreMagic p,
s,
f,
 )     (p)
 

Definition at line 546 of file fixmem.cpp.


Function Documentation

void CCFree LPVOID  Buf  ) 
 

Like malloc but does not throw exceptions. Change size of memory block, similar to realloc but does not throw exceptions. Like free.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/10/93
Parameters:
pointer to memory allocated with CCMalloc (or NULL) [INPUTS]
None [OUTPUTS]
Returns:
None

Errors: None

See also:
CCMalloc;free

Definition at line 753 of file fixmem.cpp.

00754 {
00755 #ifdef USE_CRIT
00756     CCMallocCriticalSection Cs;
00757 #endif
00758 
00759 #ifdef _OUTPUT_DEBUG
00760     if (Buf)
00761     {
00762         CCMallocList* p = (CCMallocList*) Buf;
00763         p--;
00764         TotalMalloced -= p->Size;
00765         TRACE( _T("UnMalloced %ld (-%ld in %s at %ld)\n"),TotalMalloced, p->Size, p->Filename, p->LineNum);
00766     }
00767 
00768 #endif
00769     // check magic longword (and remove it to find double-frees)
00770     Buf = CheckMagic( Buf, TRUE );
00771 
00772 //  TRACE( _T("CCFree at 0x%08x (0x%08x)\n"), Buf, ((char*)Buf - MAGIC_EXTRA));
00773 
00774     // then free it
00775     free( Buf );
00776 }

TunedMemory* GetTunedMemManager  ) 
 

Finds the Tuned Memory manager so that people that need to know get ask it for memory etc.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/5/95
Returns:
A pointer to the tuned memory manager

Definition at line 794 of file fixmem.cpp.

00795 {
00796     return &TheTunedMemoryManager;
00797 }

size_t RetailCCGetBlockSize LPVOID  Block  ) 
 

Finds out how big a block of ram someone asked for when they called CCMalloc.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/5/95
Parameters:
Block - the alloc'ed block we want to know the size of [INPUTS]
Returns:
the size of the block that was asked for

Definition at line 673 of file fixmem.cpp.

00674 {
00675 #ifdef USE_CRIT
00676     CCMallocCriticalSection Cs;
00677 #endif
00678 
00679     if (Block==NULL)
00680         return 0;
00681 
00682 #if !defined(__WXMAC__)
00683     return _msize(Block);
00684 #else
00685     return malloc_size(Block);
00686 #endif
00687 }

LPVOID RetailCCMalloc UINT32  Size  ) 
 

Like malloc but does not throw exceptions.

LPVOID RetailCCMalloc( UINT32 size )

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/94
Parameters:
size of memory required (must be non-zero) [INPUTS]
None [OUTPUTS]
Returns:
Pointer to new block, or NULL if failed.

Errors: None.

See also:
CCFree;RetailCCRealloc;malloc

Definition at line 565 of file fixmem.cpp.

00566 {
00567 #ifdef USE_CRIT
00568     CCMallocCriticalSection Cs;
00569 #endif
00570 
00571     if (Size==0L)                                                           // size of 0 is illegal
00572         return NULL;
00573 
00574     if (checksize(Size))
00575         return NULL;                                                        // if too big
00576 
00577     // save VC++s internal fail-memory pointer and reset it so nothing special occurs
00578     // if memory runs out
00579 #if !defined(__WXMAC__)
00580     _PNH old_handler = _set_new_handler( NULL );
00581 #else
00582     new_handler pnh = set_new_handler(NULL);
00583 #endif
00584 
00585     // call malloc to get the memory or a NULL pointer
00586     void *p = malloc( (size_t)Size );
00587     
00588     // repair the function pointer to its old value and return our pointer
00589 #if !defined(__WXMAC__)
00590     _set_new_handler( old_handler );
00591 #else
00592     set_new_handler(pnh);
00593 #endif
00594 
00595     // set the error if it didn't work
00596     if (p == NULL)
00597         Error::SetError(_R(IDS_OUT_OF_MEMORY));
00598 
00599     return p;
00600 }

LPVOID RetailCCRealloc LPVOID  Buf,
UINT32  Size
 

Change size of memory block, similar to realloc but does not throw exceptions.

LPVOID RetailCCRealloc( LPVOID buf, UINT32 size )

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/94
Parameters:
Pointer to block allocated with CCMalloc (can be NULL) and new size (must be non-zero) [INPUTS]
Returns:
Pointer to new block (might have changed) or NULL if cannot reallocate (old block will remain intact)

Errors: None.

See also:
RetailCCMalloc;CCFree;realloc

Definition at line 620 of file fixmem.cpp.

00621 {
00622 #ifdef USE_CRIT
00623     CCMallocCriticalSection Cs;
00624 #endif
00625 
00626     if (Size==0L)                                                           // size of 0 is illegal
00627         return NULL;
00628 
00629     if (checksize(Size))
00630         return NULL;                                                            // if too big
00631 
00632     // save VC++s internal fail-memory pointer and reset it so nothing special occurs
00633     // if memory runs out
00634 #if !defined(__WXMAC__)
00635     _PNH old_handler = _set_new_handler( NULL );
00636 #else
00637     new_handler pnh = set_new_handler(NULL);
00638 #endif
00639 
00640     // call realloc
00641     void *p = realloc( Buf, (size_t)Size );
00642     
00643     // finally repair the function pointer to its old value and return our pointer
00644 #if !defined(__WXMAC__)
00645     _set_new_handler( old_handler );
00646 #else
00647     set_new_handler(pnh);
00648 #endif
00649 
00650     // set the error if it didn't work
00651     if (p == NULL)
00652         Error::SetError(_R(IDS_OUT_OF_MEMORY));
00653 
00654     // return result, storing magic word
00655     return p;
00656 }


Variable Documentation

TunedMemory TheTunedMemoryManager [static]
 

Definition at line 126 of file fixmem.cpp.


Generated on Sat Nov 10 03:49:31 2007 for Camelot by  doxygen 1.4.4