source: trunk/source/global/management/test/DeallocatorTest.cc @ 1346

Last change on this file since 1346 was 1315, checked in by garnier, 14 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 3.4 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: DeallocatorTest.cc,v 1.3 2006/06/29 19:04:49 gunter Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
29//
30//
31// ----------------------------------------------------------------------
32#include "G4Timer.hh"
33#include "G4Allocator.hh"
34#include "G4ThreeVector.hh"
35#include "globals.hh"
36#include "G4ios.hh"
37
38class G4Type
39{
40  public:
41
42    G4Type(){}
43    ~G4Type(){}
44
45    inline void *operator new(size_t);
46    inline void operator delete(void *aObj);
47
48  private:
49 
50    G4int         i1, i2, i3, i4, i5, i6, i7;
51    G4double      d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13;
52    G4double*     p1, p2, p3, p4, p5, p6, p7;
53    G4ThreeVector v1, v2, v3;
54};
55
56G4Allocator<G4Type> aAllocator;
57
58inline void* G4Type::operator new(size_t)
59{
60  void *aValue;
61  aValue = (void *) aAllocator.MallocSingle();
62  return aValue;
63}
64
65inline void G4Type::operator delete(void *aValue)
66{
67  aAllocator.FreeSingle((G4Type *) aValue);
68}
69
70int main()
71{
72  G4Timer timer;
73  G4Type* pObj = 0;
74  const size_t maxiter = 10000000;
75  const size_t modulo  = 1000000;
76
77  timer.Start();
78  for (size_t i=0; i<maxiter; i++)
79  {
80    pObj = new G4Type();
81    if (i%modulo == 0)
82    {
83      G4cout << "Clearing storage ..." << G4endl
84             << "   allocator size before: "
85             << aAllocator.GetAllocatedSize()
86             << " bytes" << G4endl;
87      aAllocator.ResetStorage();
88      G4cout << "   allocator size after : "
89             << aAllocator.GetAllocatedSize()
90             << " bytes" << G4endl;
91    }
92  }
93  for (size_t j=0; j<maxiter; j++)
94  {
95    delete pObj;
96  }
97  timer.Stop(); 
98
99  G4Type ref;
100  G4cout << "Object size: " << sizeof(ref) << G4endl
101         << "System time: " << timer.GetSystemElapsed() << G4endl
102         << "User time  : " << timer.GetUserElapsed() << G4endl;
103
104  return 0;
105}
Note: See TracBrowser for help on using the repository browser.