00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * 00004 * The IPPL Framework 00005 * 00006 * This program was prepared by PSI. 00007 * All rights in the program are reserved by PSI. 00008 * Neither PSI nor the author(s) 00009 * makes any warranty, express or implied, or assumes any liability or 00010 * responsibility for the use of this software 00011 * 00012 * Visit http://www.acl.lanl.gov/POOMS for more details 00013 * 00014 ***************************************************************************/ 00015 00016 // -*- C++ -*- 00017 /*************************************************************************** 00018 * 00019 * The IPPL Framework 00020 * 00021 * 00022 * Visit http://people.web.psi.ch/adelmann/ for more details 00023 * 00024 ***************************************************************************/ 00025 00026 // include files 00027 00028 #include "Utility/DiscBuffer.h" 00029 #include "Utility/PAssert.h" 00030 #include <stdlib.h> 00031 00032 00034 // Method definitions for DiscBuffer 00036 00037 // Static storage 00038 00039 long DiscBuffer::size_s = 0; 00040 char *DiscBuffer::buffer_s = 0; 00041 00042 // Some static variables used for statistics, these are really 00043 // hacks so don't count on them. 00044 00045 double DiscBuffer::readtime = 0.0; 00046 double DiscBuffer::writetime = 0.0; 00047 long DiscBuffer::readbytes = 0; 00048 long DiscBuffer::writebytes = 0; 00049 00050 00052 // The default constructor does nothing, this class is mainly an 00053 // interface to the static data. 00054 00055 DiscBuffer::DiscBuffer() 00056 { 00057 } 00058 00059 00061 // The destructor will delete the buffer storage if it has been 00062 // previously created. 00063 00064 DiscBuffer::~DiscBuffer() 00065 { 00066 if (buffer_s != 0) 00067 #ifdef IPPL_DIRECTIO 00068 free(buffer_s); 00069 #else 00070 delete [] buffer_s; 00071 #endif 00072 00073 size_s = 0; 00074 buffer_s = 0; 00075 } 00076 00077 00079 // Make sure the current buffer is at least as large as the given 00080 // size. If it is not, reallocate (but do not copy). In either case, 00081 // return the buffer pointer. 00082 00083 void *DiscBuffer::resize(long sz) 00084 { 00085 PAssert(sz >= 0); 00086 00087 if (sz > size_s) 00088 { 00089 // Reset our existing size 00090 00091 size_s = sz; 00092 00093 // Free the old buffer, if necessary, and create a new one 00094 00095 #ifdef IPPL_DIRECTIO 00096 if (buffer_s != 0) 00097 { 00098 free(buffer_s); 00099 buffer_s = 0; 00100 } 00101 buffer_s = (char *)valloc(size_s); 00102 #else 00103 if (buffer_s != 0) 00104 { 00105 delete [] buffer_s; 00106 buffer_s = 0; 00107 } 00108 buffer_s = new char[size_s]; 00109 #endif 00110 00111 PAssert(buffer_s != 0); 00112 } 00113 00114 return buffer(); 00115 } 00116 00117 00119 // Create a single global instance of a DiscBuffer so that something 00120 // will delete the storage when it is done. 00121 00122 DiscBuffer ipplGlobalDiscBuffer_g; 00123 00124 00125 /*************************************************************************** 00126 * $RCSfile: DiscBuffer.cpp,v $ $Author: adelmann $ 00127 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $ 00128 * IPPL_VERSION_ID: $Id: DiscBuffer.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $ 00129 ***************************************************************************/