/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to parse/xerces-dom.cpp

  • Committer: Suren A. Chilingaryan
  • Date: 2009-09-23 17:13:04 UTC
  • Revision ID: csa@dside.dyndns.org-20090923171304-osvtr4zqb29h11kd
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include <xercesc/framework/MemBufInputSource.hpp>
5
5
#include <xercesc/parsers/XercesDOMParser.hpp>
6
6
 
7
 
 
8
7
#include "tools.h"
9
8
 
10
9
#if defined(XERCES_HAS_CPP_NAMESPACE)
11
10
    XERCES_CPP_NAMESPACE_USE
12
11
#endif
13
12
 
 
13
 
 
14
#ifdef FAST_MEMORY
 
15
#define FASTMM_BUF_SIZE 134217728
 
16
class FASTMemoryManager : public MemoryManager {
 
17
 protected:
 
18
    void *buf;
 
19
    int cursize;
 
20
    int pos;
 
21
 public:
 
22
    FASTMemoryManager() {
 
23
        cursize = FASTMM_BUF_SIZE;
 
24
        pos = 0;
 
25
        buf = malloc(FASTMM_BUF_SIZE);
 
26
        if (!buf) exit(-1);
 
27
    }
 
28
    
 
29
    void * allocate (XMLSize_t size) {
 
30
        void *res;
 
31
 
 
32
        int mod = size%16;
 
33
        if (mod) bsize += 16-mod;
 
34
 
 
35
        if (pos + size > cursize) {
 
36
            while (pos + size > cursize) cursize *= 2;
 
37
            buf = realloc(buf, cursize);
 
38
            if (!buf) exit(-1);
 
39
        }
 
40
        
 
41
        res = (char*)buf+pos;
 
42
        pos += size;
 
43
        return res;
 
44
    }
 
45
    
 
46
    void deallocate (void *p) {
 
47
    }
 
48
    
 
49
    void clean() {
 
50
        pos = 0;
 
51
    }
 
52
    
 
53
    ~FASTMemoryManager() {
 
54
        free(buf);
 
55
    }
 
56
} fastmm;
 
57
#endif /* FAST_MEMORY */
 
58
 
 
59
 
 
60
 
14
61
void initXML(struct TestData *td) {
15
62
    XMLPlatformUtils::Initialize();
 
63
#ifdef FAST_MEMORY
 
64
#endif /* FAST_MEMORY */
16
65
}
17
66
 
18
67
void releaseXML(struct TestData *td) {
 
68
#ifdef FAST_MEMORY
 
69
#endif /* FAST_MEMORY */
19
70
    XMLPlatformUtils::Terminate();
20
71
}
21
72
 
24
75
    MemBufInputSource *buffer;
25
76
    XercesDOMParser *parser;
26
77
 
 
78
#ifdef FAST_MEMORY
 
79
    fastmm.clean();
 
80
    parser = new XercesDOMParser(NULL,&fastmm);
 
81
#else
27
82
    parser = new XercesDOMParser;
 
83
#endif /* FAST_MEMORY */
 
84
 
28
85
    buffer=new MemBufInputSource((XMLByte*)td->xml,td->xmllen,(const char*)&id);
29
86
    buffer->setCopyBufToStream(false);
30
87
    parser->parse(*buffer);