aligned_alloc_test.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. Copyright 2014 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include <boost/align/aligned_alloc.hpp>
  8. #include <boost/align/is_aligned.hpp>
  9. #include <boost/core/lightweight_test.hpp>
  10. #include <cstring>
  11. void test(std::size_t alignment)
  12. {
  13. {
  14. void* p = boost::alignment::aligned_alloc(alignment, alignment + 1);
  15. BOOST_TEST(p != 0);
  16. BOOST_TEST(boost::alignment::is_aligned(p, alignment));
  17. std::memset(p, 0, alignment);
  18. boost::alignment::aligned_free(p);
  19. }
  20. {
  21. void* p = boost::alignment::aligned_alloc(alignment, 1);
  22. BOOST_TEST(p != 0);
  23. BOOST_TEST(boost::alignment::is_aligned(p, alignment));
  24. std::memset(p, 0, 1);
  25. boost::alignment::aligned_free(p);
  26. }
  27. {
  28. void* p = boost::alignment::aligned_alloc(alignment, 0);
  29. boost::alignment::aligned_free(p);
  30. }
  31. }
  32. int main()
  33. {
  34. test(1);
  35. test(2);
  36. test(4);
  37. test(8);
  38. test(16);
  39. test(32);
  40. test(64);
  41. test(128);
  42. return boost::report_errors();
  43. }