source: icXML/icXML-devel/src/icxercesc/util/XMemory.cpp @ 3157

Last change on this file since 3157 was 3157, checked in by cameron, 6 years ago

Fixes for icXML 0.9

File size: 2.5 KB
Line 
1/*
2 * Unless required by applicable law or agreed to in writing, software
3 * distributed under the License is distributed on an "AS IS" BASIS,
4 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5 * See the License for the specific language governing permissions and
6 * limitations under the License.
7 */
8
9/*
10 * $Id: XMemory.cpp 635226 2008-03-09 12:04:39Z borisk $
11 */
12
13
14// ---------------------------------------------------------------------------
15//  Includes
16// ---------------------------------------------------------------------------
17#include <xercesc/util/XMemory.hpp>
18
19#include <icxercesc/util/PlatformUtils.hpp>
20#include <xercesc/framework/MemoryManager.hpp>
21#include <assert.h>
22
23XERCES_CPP_NAMESPACE_BEGIN
24
25#define HEADER_SIZE (XMLPlatformUtils::alignPointerForNewBlockAllocation(sizeof(MemoryManager*)))
26
27void* XMemory::operator new(size_t size)
28{
29    void* const block = XMLPlatformUtils::fgMemoryManager->allocate(HEADER_SIZE + size);
30    *(MemoryManager**)block = XMLPlatformUtils::fgMemoryManager;
31    return (char*)block + HEADER_SIZE;
32}
33
34#if defined(XERCES_MFC_SUPPORT)
35
36void* XMemory::operator new(size_t size, const char* /*file*/, int /*line*/)
37{
38        return operator new(size);
39}
40
41void XMemory::operator delete(void* p, const char* /*file*/, int /*line*/)
42{
43        operator delete(p);
44}
45
46#endif
47
48void* XMemory::operator new(size_t size, MemoryManager* manager)
49{
50    void * const block = manager->allocate(HEADER_SIZE + size);
51    *(MemoryManager**)block = manager;
52    return (char*)block + HEADER_SIZE;
53}
54
55void* XMemory::operator new(size_t /*size*/, void* ptr)
56{
57        return ptr;
58}
59
60void XMemory::operator delete(void * p)
61{
62        if (p != 0)
63        {
64        void* const block = (char*)p - HEADER_SIZE;
65                MemoryManager* const manager = *(MemoryManager**)block;
66                manager->deallocate(block);
67        }
68}
69
70//The Borland compiler is complaining about duplicate overloading of delete
71#if !defined(XERCES_NO_MATCHING_DELETE_OPERATOR)
72
73
74void XMemory::operator delete(void* p, MemoryManager* manager)
75{
76        if (p != 0)
77        {
78        void* const block = (char*)p - HEADER_SIZE;
79                /***
80                 * assert(*(MemoryManager**)block == manager);
81                 *
82                 * NOTE: for compiler which can't properly trace the memory manager used in the
83                 *       placement new, we use the memory manager embedded in the memory rather
84                 *       than the one passed in
85                 */
86                MemoryManager* pM = *(MemoryManager**)block;
87                pM->deallocate(block);
88        }
89}
90
91
92void XMemory::operator delete(void* /*p*/, void* /*ptr*/)
93{
94}
95
96#endif
97
98#undef HEADER_SIZE
99
100XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.