Advertisement
Guest User

shared_ptr<T[]> example

a guest
Feb 19th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. // Initially this:
  2. unique_ptr<BYTE[]> paddedInput(add_pad_border(pImg, nWidth, nHeight, nPatch));
  3. // and in the main loop several calls to
  4. inline void ExtractPatch(T const * const from, int const x, int const y, int const yStep, int const length, T * const to) {/* ... */}
  5. // like this:
  6. ExtractPatch(paddedInput.get(), x, y * extendedWidth, extendedWidth, patchLength, w1);
  7. ////////////////////////////// 10.7s
  8.  
  9. // Then changed to:
  10. BYTE const * const paddedInput_ = add_pad_border(pImg, nWidth, nHeight, nPatch);
  11. vector<BYTE> paddedInput(paddedInput_, paddedInput_ + (nWidth + 2 * nPatch) * (nHeight + 2 * nPatch));
  12. delete [] paddedInput_;
  13. // With the same inline function called like this:
  14. ExtractPatch(&paddedInput[0], x, y * extendedWidth, extendedWidth, patchLength, w1);
  15. ////////////////////////////// 9.4s
  16.  
  17. // Lastly with vector parameter
  18. inline void ExtractPatch(std::vector<T> const & from, int const x, int const y, int const yStep, int const length, T * const to) {/* ... */}
  19. // and calls like:
  20. ExtractPatch(paddedInput, wx - nPatch, windowRow , extendedWidth, patchLength, w2);
  21. ////////////////////////////// 14.9s
  22.  
  23. // All in release mode with 8 cores fully utilized.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement