Patch: delete_test1.cpp
Jeffrey Oldham
oldham at codesourcery.com
Fri May 25 20:30:11 UTC 2001
Compiling src/Utilities/tests/delete_test1.cpp showed that the vector
type `Array_t' was declared to store doubles but actually stored
integers. Also, a call to std::memmove() illegally converted vector
iterators to pointers. The alternative call to std::copy() is instead
used.
Considerable discussion between Jim Crotinger and Jeffrey D. Oldham on
pooma-dev annoyed other people on the list. The issue, also present
in some Domain code, is that using std::memmove() requires converting
a vector iterator to a pointer. Jeffrey Oldham objects to this
violation of the abstraction barrier and was not able to show a
significant speedup using std::memmove() rather than std::copy(). Jim
Crotinger says he measured significant speed-up using std::memmove()
in early 2000.
For the record, one way to obtain a pointer to a vector location that
the gcc 3.0 compiler accepts is
const Array_t::pointer data_begin_ptr = &(data[0]);
2001 May 25 Jeffrey D. Oldham <oldham at codesourcery.com>
* delete_test1.cpp (Array_t): s/vector<double>/vector<int>/
(delete_shiftup_test2): Remove "optimization" call to memmove.
Tested on sequential Linux using gcc 3.0 by compiling the program
Approved by Jim Crotinger
Thanks,
Jeffrey D. Oldham
oldham at codesourcery.com
-------------- next part --------------
Index: delete_test1.cpp
===================================================================
RCS file: /home/pooma/Repository/r2/src/Utilities/tests/delete_test1.cpp,v
retrieving revision 1.7
diff -c -p -r1.7 delete_test1.cpp
*** delete_test1.cpp 2001/03/21 00:56:09 1.7
--- delete_test1.cpp 2001/05/25 20:20:55
*************** int main(int argc, char *argv[])
*** 94,100 ****
typedef std::vector<int> KillList_t;
! typedef std::vector<double> Array_t;
void delete_shiftup_orig (Array_t &data, const KillList_t &killList);
void delete_shiftup_test1(Array_t &data, const KillList_t &killList);
--- 94,100 ----
typedef std::vector<int> KillList_t;
! typedef std::vector<int> Array_t;
void delete_shiftup_orig (Array_t &data, const KillList_t &killList);
void delete_shiftup_test1(Array_t &data, const KillList_t &killList);
*************** void delete_shiftup_test2(Array_t &data,
*** 618,635 ****
if (inext < killed)
copy_end_index = killList[inext];
! const int length = copy_end_index - copy_begin_index;
!
! if (length < 100)
! std::copy(data_begin + copy_begin_index,
! data_begin + copy_end_index,
! data_begin + insert_index);
! else
! std::memmove(data_begin + insert_index,
! data_begin + copy_begin_index,
! sizeof(Array_t::value_type)*length);
!
! insert_index += length;
}
}
--- 618,627 ----
if (inext < killed)
copy_end_index = killList[inext];
! std::copy(data_begin + copy_begin_index,
! data_begin + copy_end_index,
! data_begin + insert_index);
! insert_index += copy_end_index - copy_begin_index;
}
}
More information about the pooma-dev
mailing list