OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
DiscBuffer.cpp
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 *
4 * The IPPL Framework
5 *
6 * This program was prepared by PSI.
7 * All rights in the program are reserved by PSI.
8 * Neither PSI nor the author(s)
9 * makes any warranty, express or implied, or assumes any liability or
10 * responsibility for the use of this software
11 *
12 * Visit www.amas.web.psi for more details
13 *
14 ***************************************************************************/
15
16// -*- C++ -*-
17/***************************************************************************
18 *
19 * The IPPL Framework
20 *
21 *
22 * Visit http://people.web.psi.ch/adelmann/ for more details
23 *
24 ***************************************************************************/
25
26// include files
27
28#include "Utility/DiscBuffer.h"
29#include "Utility/PAssert.h"
30#include <cstdlib>
31
32
34// Method definitions for DiscBuffer
36
37// Static storage
38
39long DiscBuffer::size_s = 0;
40char *DiscBuffer::buffer_s = 0;
41
42// Some static variables used for statistics, these are really
43// hacks so don't count on them.
44
45double DiscBuffer::readtime = 0.0;
46double DiscBuffer::writetime = 0.0;
49
50
52// The default constructor does nothing, this class is mainly an
53// interface to the static data.
54
56{
57}
58
59
61// The destructor will delete the buffer storage if it has been
62// previously created.
63
65{
66 if (buffer_s != 0)
67 delete [] buffer_s;
68
69 size_s = 0;
70 buffer_s = 0;
71}
72
73
75// Make sure the current buffer is at least as large as the given
76// size. If it is not, reallocate (but do not copy). In either case,
77// return the buffer pointer.
78
79void *DiscBuffer::resize(long sz)
80{
81 PAssert_GE(sz, 0);
82
83 if (sz > size_s)
84 {
85 // Reset our existing size
86 size_s = sz;
87
88 // Free the old buffer, if necessary, and create a new one
89 if (buffer_s != 0)
90 {
91 delete [] buffer_s;
92 buffer_s = 0;
93 }
94 buffer_s = new char[size_s];
96 }
97
98 return buffer();
99}
100
101
103// Create a single global instance of a DiscBuffer so that something
104// will delete the storage when it is done.
105
107
108
109/***************************************************************************
110 * $RCSfile: DiscBuffer.cpp,v $ $Author: adelmann $
111 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
112 * IPPL_VERSION_ID: $Id: DiscBuffer.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
113 ***************************************************************************/
DiscBuffer ipplGlobalDiscBuffer_g
Definition: DiscBuffer.cpp:106
#define PAssert(c)
Definition: PAssert.h:102
#define PAssert_GE(a, b)
Definition: PAssert.h:109
static long writebytes
Definition: DiscBuffer.h:85
static double writetime
Definition: DiscBuffer.h:83
static void * buffer()
Definition: DiscBuffer.h:55
static long readbytes
Definition: DiscBuffer.h:84
static long size_s
Definition: DiscBuffer.h:90
static char * buffer_s
Definition: DiscBuffer.h:94
static double readtime
Definition: DiscBuffer.h:82
static void * resize(long sz)
Definition: DiscBuffer.cpp:79