fixmem.cpp

Go to the documentation of this file.
00001 // $Id: fixmem.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 // fixed memory allocator (used in preference to malloc/free etc)
00100 
00101 
00102 #include "camtypes.h"
00103 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00104 #if !defined(__WXMAC__)
00105 #include <malloc.h>
00106 #else
00107 #include <malloc/malloc.h>
00108 #endif
00109 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 
00112 #if !defined(EXCLUDE_FROM_XARLIB)
00113 #include "tunemem.h"
00114 #endif
00115 
00116 #if defined( __WXMSW__ )
00117 #include <new.h>
00118 #elif defined( __WXMAC__ )
00119 #include <new>
00120 #endif
00121 
00122 //#include "ralphcri.h" // for critical sections
00123 //#define USE_CRIT 1
00124 
00125 #if !defined(EXCLUDE_FROM_XARLIB)
00126 static TunedMemory TheTunedMemoryManager;
00127 #endif
00128 
00129 // Happy chappie critical crappy (for ralphm, threads and so forth)
00130 CRITICAL_SECTION CCMallocCriticalSection::sm_Section;
00131 BOOL CCMallocCriticalSection::sm_bInit = FALSE;
00132 
00133 #define checksize(x)    FALSE
00134 
00135 #ifdef _DEBUG
00136 
00137 typedef struct CCMallocList
00138 {
00139     UINT32              GuardWord;
00140     CCMallocList       *Next;
00141     CCMallocList       *Prev;
00142     size_t              Size;
00143     void               *Start;
00144     char                Filename[22];
00145     INT32                   LineNum;
00146 } CCMallocList;
00147 
00148 static CCMallocList *TraceListHead = NULL;
00149 
00150 
00151 #define MAGIC_LONGWORD  0xDEADBEEF
00152 #define MAGIC_EXTRA     sizeof(CCMallocList)
00153 
00154 
00155 #ifdef _OUTPUT_DEBUG
00156 static INT32 TotalMalloced = 0;
00157 #endif
00158 
00159 /********************************************************************************************
00160 
00161     static void *CheckMagic( void* Block, BOOL Destroy )
00162 
00163     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00164     Created:    15/6/94
00165     Inputs:     Block - pointer to memory block. If Destroy is TRUE will remove magic
00166                 marker so detect double-freeing.
00167     Outputs:    None
00168     Returns:    Pointer before magic in block. Returns NULL if Block was null on input, or
00169                 if the block is not recognised as one of ours.
00170     Purpose:    For debug builds to ensure the magic longword marker is in the block.
00171                 If Destroy is TRUE then removes block from memory tracing list.
00172                 Stubbed away in retail builds.
00173     Scope:      Static to fixmem.cpp
00174 
00175 ********************************************************************************************/
00176 
00177 static void *CheckMagic( void* Block, BOOL Destroy )
00178 {
00179     if (Block != NULL)
00180     {
00181         CCMallocList *p = (CCMallocList*)Block;
00182 
00183         // decrement pointer by sizeof(CCMallocList)
00184         p--;
00185 
00186         if ( p->GuardWord == MAGIC_LONGWORD )
00187         {
00188             if (Destroy)
00189             {
00190                 p->GuardWord = 0xF000BAAA;                      // if it was our marker then destroy it
00191 
00192                 if (p == TraceListHead)
00193                     TraceListHead = p->Next;
00194 
00195                 if (p->Next != NULL)
00196                     p->Next->Prev = p->Prev;
00197 
00198                 if (p->Prev != NULL)
00199                     p->Prev->Next = p->Next;
00200             }
00201         }
00202         else
00203         {
00204             // if marker not there then either we didn't alloc it, or it has been freed for
00205             // the second time
00206             ENSURE (FALSE, "CCFree/realloc called on memory that was not CCMalloced");
00207             return NULL;                                // so no-one tries to use it
00208         }
00209         Block = p;                                      // use real address to free
00210     }
00211     return Block;
00212 }
00213 
00214 /********************************************************************************************
00215 
00216     static void *StoreMagic( void *Block , UINT32 Size , LPCSTR Filename , INT32 Line )
00217 
00218     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com> (and Gerry)
00219     Created:    15/6/94
00220     Inputs:     Block - pointer to memory block. Stores magic longword in there.
00221     Outputs:    None
00222     Returns:    The address just past that to the caller for use by the user.
00223     Purpose:    For debug builds to insert magic longword marker and other memory tracing
00224                 info in the block. Stubbed away in retail builds.
00225     Scope:      Static to fixmem.cpp
00226 
00227 ********************************************************************************************/
00228 
00229 static void *StoreMagic( void *Block , size_t Size , LPCSTR Filename , INT32 Line )
00230 {
00231     if (Block != NULL)
00232     {
00233         CCMallocList *p = (CCMallocList*)Block;
00234         p->GuardWord = MAGIC_LONGWORD;                                  // store magic
00235 
00236         p->Size = Size;
00237 
00238         // Fill in the details about the file position
00239         if (Filename != NULL)
00240         {   
00241             // copy the string passed in and note the line number
00242             size_t      Count = strlen( Filename );
00243             if ( Count>21 )
00244             {
00245                 // The string was too long, so we have to copy just the last 22 chars in it
00246                 Filename += Count-21;
00247             }
00248 
00249             // copy the end of the string into the space I have for it
00250             strcpy( p->Filename, Filename );
00251             p->LineNum = Line;
00252         }
00253         else
00254         {
00255             // set the fields to null values
00256             strcpy( p->Filename, "Unknown File" );                          // Was a IDS const, but too much effort for debug
00257             p->LineNum = 0;
00258         }
00259 
00260         p->Start = ((char*)Block) + MAGIC_EXTRA;                            // and return user bigger pointer
00261         return p->Start;
00262     }
00263 
00264     return NULL;
00265 }
00266 
00267 
00268 /********************************************************************************************
00269 
00270     static void LinkMagic( void *Block )
00271 
00272     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
00273     Created:    1/9/94
00274     Inputs:     Block - pointer to memory block.
00275     Outputs:    None
00276     Purpose:    For debug builds to link the block into the tracking list. Stubbed away in
00277                 retail builds.
00278     Scope:      Static to fixmem.cpp
00279 
00280 ********************************************************************************************/
00281 
00282 static void LinkMagic( void *Block )
00283 {
00284     if (Block != NULL)
00285     {
00286         CCMallocList *p = (CCMallocList*)Block;
00287 
00288         p->GuardWord = MAGIC_LONGWORD;          // store magic word
00289 
00290         p->Next = TraceListHead;
00291         p->Prev = NULL;
00292 
00293         if (TraceListHead != NULL)
00294             TraceListHead->Prev = p;
00295 
00296         TraceListHead = p;
00297     }
00298 }
00299 
00300 
00301 /********************************************************************************************
00302 
00303 >   void DumpCCMallocTrace(void)
00304 
00305     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
00306     Created:    1/9/94
00307     Inputs:     None
00308     Outputs:    None
00309     Returns:    None
00310     Purpose:    Lists any unreleased memory blocks
00311     Errors:     None
00312     SeeAlso:    LinkMagic;CheckMagic;StoreMagic
00313     
00314 ********************************************************************************************/
00315 
00316 void DumpCCMallocTrace(void)
00317 {
00318     if (TraceListHead != NULL)
00319     {
00320         TRACE( _T("\n\n...CCMalloc leaks detected...\n\n"));
00321 
00322         CCMallocList *Ptr = TraceListHead;
00323 
00324         while (Ptr != NULL)
00325         {
00326 #if 0 != wxUSE_UNICODE
00327             TCHAR pFilename[22];
00328             camMbstowcs(pFilename, Ptr->Filename, 22);
00329 #else
00330             TCHAR* pFilename = Ptr->Filename;
00331 #endif
00332             TRACE( _T("%ld bytes allocated in %s at line %ld\n"),Ptr->Size, pFilename, Ptr->LineNum);
00333             Ptr = Ptr->Next;
00334         }
00335 
00336         TRACE( _T("\n...End of CCMalloc leaks...\n\n"));
00337     }
00338 }
00339 
00340 
00341 /********************************************************************************************
00342 
00343 >   LPVOID DebugCCMalloc(UINT32 size, LPCSTR Filename, INT32 Line)
00344 
00345     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
00346     Created:    1/9/94
00347     Inputs:     size of block required
00348                 source filename called from (supplied by macro)
00349                 line number of call (supplied by macro)
00350     Outputs:    None
00351     Returns:    None
00352     Purpose:    A version of malloc which does not throw exceptions and provides source file
00353                 and line number tracing.
00354     Errors:     Out of memory
00355     SeeAlso:    RetailCCMalloc;malloc
00356 
00357 ********************************************************************************************/
00358 
00359 LPVOID DebugCCMalloc(size_t Size, LPCSTR Filename, INT32 Line)
00360 {
00361 #ifdef USE_CRIT
00362     CCMallocCriticalSection Cs;
00363 #endif
00364 
00365     if (Size==0L)                                                           // size of 0 is illegal
00366     {
00367         ENSURE(FALSE, "Someone asked for 0 bytes");
00368         return NULL;
00369     }
00370 
00371 #ifdef _OUTPUT_DEBUG
00372     TotalMalloced += Size;
00373     TRACE( _T("Malloced %ld (+%ld in %s at line %ld)\n"),TotalMalloced,Size, Filename, Line);
00374 #endif
00375 
00376     size_t              NewSize = Size + MAGIC_EXTRA;
00377 
00378     if (checksize(NewSize))
00379         return NULL;                                                        // if too big
00380 
00381     // save VC++s internal fail-memory pointer and reset it so nothing special occurs
00382     // if memory runs out
00383 #if !defined(__WXMAC__)
00384     _PNH old_handler = _set_new_handler( NULL );
00385 #else
00386     new_handler pnh = set_new_handler(NULL);
00387 #endif
00388 
00389     // call malloc to get the memory or a NULL pointer
00390     void *p = malloc( (size_t)NewSize );
00391 
00392     // The next line is for debug purposes (comment out above line)
00393     //void *p = NULL;
00394     
00395     // repair the function pointer to its old value and return our pointer
00396 #if !defined(__WXMAC__)
00397     _set_new_handler( old_handler );
00398 #else
00399     set_new_handler(pnh);
00400 #endif
00401 
00402     // set the error and return if it didn't work
00403     if (p == NULL)
00404     {
00405         Error::SetError(_R(IDS_OUT_OF_MEMORY));
00406         return NULL;
00407     }
00408 
00409     // Link block in to list
00410     LinkMagic(p);
00411 
00412 //  TRACE( _T("CCMalloc at 0x%08x (0x%08x)\n"), (char*)p + MAGIC_EXTRA, p);
00413 
00414     // add the magic longword
00415     return StoreMagic(p, Size, Filename, Line);
00416 }
00417 
00418 
00419 /********************************************************************************************
00420 
00421     void DebugCCRealloc(LPVOID Buf, UINT32 Size, LPCSTR Filename, INT32 Line)
00422 
00423     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
00424     Created:    1/9/94
00425     Inputs:     pointer to memory allocated with CCMalloc (or NULL)
00426                 new size for block
00427                 source filename called from (supplied by macro)
00428                 line number of call (supplied by macro)
00429     Outputs:    None
00430     Returns:    None
00431     Purpose:    A version of realloc which does not throw exceptions and provides source file
00432                 and line number tracing.  DO NOT CALL.  Use CCRealloc instead.
00433     Errors:     Out of memory
00434     SeeAlso:    RetailCCRealloc;realloc
00435 
00436 ********************************************************************************************/
00437 
00438 LPVOID DebugCCRealloc(LPVOID Buf, size_t Size, LPCSTR Filename, INT32 Line)
00439 {
00440 #ifdef USE_CRIT
00441     CCMallocCriticalSection Cs;
00442 #endif
00443 
00444     if (Size==0L)                                                           // size of 0 is illegal
00445     {
00446         ENSURE(FALSE, "Someone asked for 0 bytes");
00447         return NULL;
00448     }
00449 
00450     // check magic longword (and remove it)
00451     const LPVOID NewBuf = CheckMagic(Buf, TRUE);    // Unlink block and set deleted
00452     if (
00453         (NewBuf==NULL) &&
00454         (Buf!=NULL)
00455        )
00456     {
00457         // CheckMagic decided that it wasn't one of our blocks, so don't try to grow it
00458         return NULL;
00459     }
00460 
00461     size_t              NewSize = Size + MAGIC_EXTRA;
00462 
00463     if (checksize(NewSize))
00464         return NULL;                                                            // if too big
00465 
00466     // save VC++s internal fail-memory pointer and reset it so nothing special occurs
00467     // if memory runs out
00468 #if !defined(__WXMAC__)
00469     _PNH old_handler = _set_new_handler( NULL );
00470 #else
00471     new_handler pnh = set_new_handler(NULL);
00472 #endif
00473 
00474     // call realloc 
00475     void *p = realloc( NewBuf, (size_t)NewSize );
00476 
00477     // The next line is for test purposes (comment out above line)
00478     //void *p = NULL;
00479     
00480     // finally repair the function pointer to its old value and return our pointer
00481 #if !defined(__WXMAC__)
00482     _set_new_handler( old_handler );
00483 #else
00484     set_new_handler(pnh);
00485 #endif
00486 
00487     // set the error and return if it didn't work
00488     if (p == NULL)
00489     {
00490         Error::SetError(_R(IDS_OUT_OF_MEMORY));
00491 
00492         // Re-link old block into list
00493         LinkMagic(NewBuf);
00494 
00495         // return NULL as realloc
00496         return NULL;
00497     }
00498     else
00499     {
00500 //      TRACE( _T("CCRealloc at 0x%08x (0x%08x) is now 0x%08x (0x%08x)\n"), Buf, NewBuf, (char*)p+MAGIC_EXTRA, p);
00501         
00502         // Link new block into list
00503         LinkMagic(p);
00504 
00505         // return result, storing magic word
00506         return StoreMagic(p, Size, Filename, Line);
00507     }
00508 }
00509 
00510 
00511 
00512 /********************************************************************************************
00513 
00514 >   INT32 DebugCCGetBlockSize(LPVOID Block)
00515 
00516     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00517     Created:    1/5/95
00518     Inputs:     Block - the alloc'ed block we want to know the size of
00519     Returns:    the size of the block that was asked for
00520     Purpose:    Finds out how big a block of ram someone asked for when they called CCMalloc
00521 
00522 ********************************************************************************************/
00523 
00524 size_t DebugCCGetBlockSize(LPVOID Block)
00525 {
00526     // default to 0
00527     size_t              Size = 0;
00528 
00529     // make sure it is OK
00530     if (Block != NULL)
00531     {
00532         // Find out the size
00533         CCMallocList *p = (CCMallocList*) (((char*)Block)-MAGIC_EXTRA);
00534         Size = p->Size;
00535     }
00536 
00537     // return it
00538     return Size;
00539 }
00540 
00541 
00542 #else
00543 // retail builds stub out those fns just in case
00544 // the only one that is used is CheckMagic (in CCFree)
00545 #define CheckMagic(p,k) (p)
00546 #define StoreMagic(p,s,f,l) (p)
00547 #define LinkMagic(p)
00548 #define MAGIC_EXTRA     0
00549 
00550 /********************************************************************************************
00551 
00552     LPVOID RetailCCMalloc( UINT32 size )
00553 
00554     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
00555     Created:    1/9/94
00556     Inputs:     size of memory required (must be non-zero)
00557     Outputs:    None
00558     Returns:    Pointer to new block, or NULL if failed.
00559     Purpose:    Like malloc but does not throw exceptions.
00560     Errors:     None.
00561     SeeAlso:    CCFree;RetailCCRealloc;malloc
00562 
00563 ********************************************************************************************/
00564 
00565 LPVOID RetailCCMalloc( UINT32 Size )
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 }
00601 
00602 
00603 
00604 
00605 /********************************************************************************************
00606 
00607     LPVOID RetailCCRealloc( LPVOID buf, UINT32 size )
00608 
00609     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
00610     Created:    1/9/94
00611     Inputs:     Pointer to block allocated with CCMalloc (can be NULL) and new size (must be non-zero)
00612     Returns:    Pointer to new block (might have changed) or NULL if cannot reallocate (old block
00613                 will remain intact)
00614     Purpose:    Change size of memory block, similar to realloc but does not throw exceptions.
00615     Errors:     None.
00616     SeeAlso:    RetailCCMalloc;CCFree;realloc
00617 
00618 ********************************************************************************************/
00619 
00620 LPVOID RetailCCRealloc( LPVOID Buf, UINT32 Size )
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 }
00657 
00658 
00659 
00660 
00661 /********************************************************************************************
00662 
00663 >   size_t RetailCCGetBlockSize(LPVOID Block)
00664 
00665     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00666     Created:    1/5/95
00667     Inputs:     Block - the alloc'ed block we want to know the size of
00668     Returns:    the size of the block that was asked for
00669     Purpose:    Finds out how big a block of ram someone asked for when they called CCMalloc
00670 
00671 ********************************************************************************************/
00672 
00673 size_t RetailCCGetBlockSize(LPVOID Block)
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 }
00688 
00689 
00690 #endif
00691 
00692 
00693 
00694 /********************************************************************************************
00695 
00696 >   LPVOID CCMalloc( UINT32 size )
00697 
00698     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
00699     Created:    1/9/94
00700     Inputs:     size of memory required (must be non-zero)
00701     Outputs:    None
00702     Returns:    Pointer to new block, or NULL if failed.
00703     Purpose:    Like malloc but does not throw exceptions.
00704     Errors:     None.
00705     SeeAlso:    malloc;CCFree;CCRealloc
00706 
00707 ********************************************************************************************/
00708 /*
00709 Technical notes:
00710 This has been implemented as a macro which calls either RetailCCMalloc or DebugCCMalloc
00711 depending on whether it is a retail or debug build.
00712 
00713 ********************************************************************************************/
00714 
00715 
00716 /********************************************************************************************
00717 
00718 >   LPVOID CCRealloc( LPVOID buf, UINT32 size )
00719 
00720     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
00721     Created:    1/9/94
00722     Inputs:     Pointer to block allocated with CCMalloc (can be NULL) and new size (must be non-zero)
00723     Returns:    Pointer to new block (might have changed) or NULL if cannot reallocate (old block
00724                 will remain intact)
00725     Purpose:    Change size of memory block, similar to realloc but does not throw exceptions.
00726     Errors:     None.
00727     SeeAlso:    RetailCCMalloc;CCFree;realloc
00728 
00729 ********************************************************************************************/
00730 /*
00731 Technical notes:
00732 This has been implemented as a macro which calls either RetailCCRealloc or DebugCCRealloc
00733 depending on whether it is a retail or debug build.
00734 
00735 ********************************************************************************************/
00736 
00737 
00738 /********************************************************************************************
00739 
00740 >   void CCFree( LPBYTE buf )
00741 
00742     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00743     Created:    25/10/93
00744     Inputs:     pointer to memory allocated with CCMalloc (or NULL)
00745     Outputs:    None
00746     Returns:    None
00747     Purpose:    Like free.
00748     Errors:     None
00749     SeeAlso:    CCMalloc;free
00750 
00751 ********************************************************************************************/
00752 
00753 void CCFree( LPVOID Buf )
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 }
00777 
00778 
00779 
00780 
00781 #if !defined(EXCLUDE_FROM_XARLIB)
00782 /********************************************************************************************
00783 
00784 >   TunedMemory* GetTunedMemManager()
00785 
00786     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00787     Created:    1/5/95
00788     Returns:    A pointer to the tuned memory manager
00789     Purpose:    Finds the Tuned Memory manager so that people that need to know get ask
00790                 it for memory etc
00791 
00792 ********************************************************************************************/
00793 
00794 TunedMemory* GetTunedMemManager()
00795 {
00796     return &TheTunedMemoryManager;
00797 }
00798 #endif
00799 

Generated on Sat Nov 10 03:48:28 2007 for Camelot by  doxygen 1.4.4