Revision 617 branches/big-buffers-test_smartlist/src/df1b2-separable/df1b2f10.cpp

df1b2f10.cpp (revision 617)
43 43
 * Description not yet available.
44 44
 * \param
45 45
 */
46
test_smartlist::test_smartlist(unsigned int _bufsize,const adstring& _filename) 
46
test_smartlist::test_smartlist(const size_t _bufsize, const adstring& _filename) 
47 47
{
48 48
  allocate(_bufsize,_filename);
49 49
}
......
52 52
 * Description not yet available.
53 53
 * \param
54 54
 */
55
void test_smartlist::allocate(unsigned int _bufsize,const adstring& _filename) 
55
void test_smartlist::allocate(const size_t _bufsize, const adstring& _filename) 
56 56
{
57 57
  if (sizeof(char)>1)
58 58
  {
......
67 67
  bufsize=_bufsize;
68 68
  filename=_filename;
69 69
  //AD_ALLOCATE(true_buffer,char,bufsize+2*sizeof(double),df1b2_gradlist) 
70
  if ((true_buffer=new char[(bufsize+2)*sizeof(double) ])==0)
70
  if ((true_buffer=new char[bufsize + sizeof(double) * 2])==0)
71 71
  {
72 72
    cerr << "Allocation error in df1b2_gradlist" << endl;
73 73
    ad_exit(1);
74 74
  }
75 75
  doubleptr=(double*)true_buffer;
76
  true_buffend=true_buffer+bufsize+2*sizeof(double)-1;
76
  true_buffend = true_buffer + bufsize + sizeof(double) * 2 - 1;
77 77
  buffer=true_buffer+sizeof(double);
78 78
  *(double*)(true_buffer)=5678.9;
79
  *(double*)(true_buffer+bufsize+sizeof(double))=9876.5;
80
  //buffend=true_buffer+bufsize-1+sizeof(double);
81
  buffend=true_buffer+bufsize-1;
79
  buffend = true_buffer + sizeof(double) + bufsize;
80
  *(double*)(buffend)=9876.5;
82 81
  bptr=buffer;
83 82
  fp=open((char*)(filename), O_RDWR | O_CREAT | O_TRUNC |
84 83
                   O_BINARY, S_IREAD | S_IWRITE);
......
96 95
 * Description not yet available.
97 96
 * \param
98 97
 */
99
void test_smartlist::write(int n)
98
void test_smartlist::write(const size_t n)
100 99
{
101
  int nw=::write(fp,buffer,n);
100
  size_t nw = ::write(fp,buffer,n);
102 101
  if (nw<n)
103 102
  {
104 103
    cerr << "Error writing to file " << filename << endl;
......
113 112
void test_smartlist::rewind(void)
114 113
{
115 114
  bptr=buffer;
116
  unsigned int nbytes=0;
117 115
  if (written_flag)
118 116
  {
119 117
    lseek(fp,0L,SEEK_SET);
118
    size_t nbytes;
120 119
    // get the record size
121
    ::read(fp,&nbytes,sizeof(int));
122
    if (nbytes>bufsize)
120
    ::read(fp, &nbytes, sizeof(size_t));
121
    if (nbytes > bufsize)
123 122
    {
124 123
      cerr << "Error -- record size in file seems to be larger than"
125 124
       " the buffer it was created from " << endl 
......
131 130
    //cout << "Number of bytes read " << nr << endl;
132 131
    // skip over file postion entry in file
133 132
    // so we are ready to read second record
134
    lseek(fp,long(sizeof(off_t)),SEEK_CUR);
133
    lseek(fp, sizeof(off_t),SEEK_CUR);
135 134
  }
136 135
}
137 136

  
......
153 152
 * Description not yet available.
154 153
 * \param
155 154
 */
156
void test_smartlist::check_buffer_size(int nsize)
155
void test_smartlist::check_buffer_size(const size_t nsize)
157 156
{
158
  if ( bptr+nsize-1 > buffend)
157
  ptrdiff_t ptrdiff = buffend - bptr;
158
  if (nsize > ptrdiff)
159 159
  {
160
    if (df1b2variable::get_passnumber()==2 && !noreadflag )
160
    if (df1b2variable::get_passnumber() == 2 && !noreadflag )
161 161
    {
162 162
      read_buffer();
163 163
    }
164 164
    else
165 165
    {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff