cammemory.h

Go to the documentation of this file.
00001 // $Id: cammemory.h 1492 2006-07-20 19:19:48Z 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 // This is the Camelot Memory Manager
00100 
00101 
00102 /********************************************************************************************
00103 
00104 < Memory Manager
00105 < Dynamic Heap
00106 
00107 Comment:
00108 
00109 \b Overview \b0
00110 
00111 The dynamic heap or dynamic memory manager is used in Camelot to manage a shifting set
00112 of memory blocks.  These memory blocks are used to hold objects which are either very
00113 large (e.g. bitmaps) or which frequently change size (e.g. paths/curves etc.).  The blocks
00114 of memory are physically moved around by the memory manager to achieve the best use of the
00115 memory available.
00116 
00117 
00118 \b Access Restrictions \b0
00119 
00120 In order for a client to access the block, a handle must be used, which is translated into
00121 a physical address when access to the block is needed.  This handle is valid only as long
00122 as the block it relates to is in existence.  More importantly, the physical address
00123 associated with a given handle may change across calls to the memory manager.  In particular,
00124 the following memory manager functions may cause the mapping from a handle to a physical
00125 address to change:
00126 MonoOn
00127         ClaimBlock()
00128         ReleaseBlock()
00129         SplitBlock()
00130         RemoveBlockGaps()
00131         TidyMemory()
00132 MonoOff
00133 Any other functions will not change the physical address associated with a handle, so it
00134 is safe to call them, and still use the same physical address to access the block.  The
00135 client should be aware that the event processing structure of Camelot means that it is not
00136 safe to assume that physical addresses remain valid across calls to Windows message
00137 processing functions, as Camelot will call the TidyMemory() function on idle events, which
00138 will cause block addresses to change.
00139 
00140 These restrictions are also relevant when using the handle manager directly to point into
00141 arbitrary positions in dynamic heap blocks.  Using the handle manager, a client can obtain
00142 a handle which points to any part of their dynamic heap block.  While obtaining this handle,
00143 the client must follow the same constraints as when using a physical address obtained via a
00144 block handle.
00145 
00146 
00147 \b General Use \b0
00148 
00149 The ClaimBlock() function should be used when allocating a block of memory from the dynamic
00150 heap.  This will return a handle for this block, which can be converted to a physical address
00151 using DescribeBlock().  The client can then access the contents of the block using this
00152 address.  It is also possible to use the Handle Manager to obtain extra handles which
00153 refer to arbitrary areas within blocks - such handles are automatically deallocated when the
00154 block itself is deallocated.  This is because the Memory Manager is itself a client of the
00155 Handle Manager, and when deallocating blocks, it instructs the Handle Manager to release any
00156 handles which point into the block in question.
00157 
00158 To deallocate a block, use the ReleaseBlock() function, passing the handle of the block
00159 you wish to deallocate. Clients should \i not \i0 pass in a handle that has been allocated
00160 by the Handle Manager directly - the Memory Manager will not deallocate the correct block,
00161 and an error will usually occur.
00162 
00163 The remaining function for manipulation of blocks is SplitBlock().  This is a general
00164 purpose function which can remove or insert memory at an arbitrary point within a block.
00165 The heap block is resized to accomodate the increase or reduction in the size of the block
00166 as a result.  This will usually cause heap blocks to move, as mentioned above, and any
00167 physical addresses obtained from handles should be considered invalid, and new versions
00168 should be obtained with DescribeBlock() (or DescribeHandle() if the handle has been obtained
00169 directly from the Handle Manager rather than via the Memory Manager).
00170 
00171 
00172 \b Debugging \b0
00173 
00174 There are two debugging functions (which are only present in the DEBUG build of Camelot).
00175 The first is CheckMemory(), which walks the heap and examines special debugging information
00176 to ensure that the heap structure has not been corrupted.  If the heap has been corrupted,
00177 an assertion failure will occur, with the usual consequences.  The other function is
00178 DumpMemory() which outputs to the debugging stream (DBWIN) the overall structure of the
00179 heap - how many blocks, what size they are, whether they are in use or designated as 'holes',
00180 and how much free memory is available at the time.
00181 
00182 
00183 SeeAlso:    InitMemory;DeinitMemory;ClaimBlock;DescribeBlock;ReleaseBlock
00184 SeeAlso:    SplitBlock;RemoveBlockGaps;TidyMemory;DumpMemory;CheckMemory
00185 SeeAlso:    Handle Manager
00186 
00187 
00188 ********************************************************************************************/
00189 
00190 #ifndef INC_MEMORY
00191 #define INC_MEMORY
00192 
00193 #include "handles.h"
00194 
00195 extern BOOL     InitMemory();
00196 extern void     DeinitMemory();
00197 extern MHANDLE  ClaimBlock(size_t Size, BOOL Heavy = FALSE);
00198 extern BOOL     DescribeBlock(MHANDLE Handle, ADDR *Address, size_t *Size);
00199 extern BOOL     ReleaseBlock(MHANDLE Handle);
00200 extern BOOL     SplitBlock(MHANDLE Handle, INT32 SplitSize, UINT32 Offset);
00201 extern BOOL     IncreaseBlock(MHANDLE Handle, UINT32 NumBytes);
00202 extern BOOL     DecreaseBlock(MHANDLE Handle, UINT32 NumBytes);
00203 extern BOOL     InsertMemory(MHANDLE Handle, UINT32 Offset, UINT32 NumBytes);
00204 extern BOOL     RemoveMemory(MHANDLE Handle, UINT32 Offset, UINT32 NumBytes);
00205 extern BOOL     TidyMemory();
00206 extern void     GetMemoryStatus(UINT64* pPhysRam = NULL, UINT32* pLoadPercent = NULL);
00207 
00208 #ifdef _DEBUG
00209 extern void DumpMemory();
00210 extern void SetMemoryFailFlag(BOOL DenyRequests);
00211 
00212 #else
00213 #define DumpMemory()
00214 #define SetMemoryFailFlag(x)
00215 
00216 #endif // _DEBUG
00217 
00218 #endif // INC_MEMORY

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