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