Stxxl  1.4.0
mng/test_aligned.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  mng/test_aligned.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2009 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
00007  *
00008  *  Distributed under the Boost Software License, Version 1.0.
00009  *  (See accompanying file LICENSE_1_0.txt or copy at
00010  *  http://www.boost.org/LICENSE_1_0.txt)
00011  **************************************************************************/
00012 
00013 #define STXXL_VERBOSE_LEVEL 0
00014 #define STXXL_VERBOSE_ALIGNED_ALLOC STXXL_VERBOSE0
00015 #define STXXL_VERBOSE_TYPED_BLOCK STXXL_VERBOSE0
00016 
00017 #include <iostream>
00018 #include <vector>
00019 #include <stxxl/mng>
00020 
00021 #define BLOCK_SIZE (1024 * 1024)
00022 
00023 struct type
00024 {
00025     int i;
00026     ~type() { }
00027 };
00028 
00029 typedef stxxl::typed_block<BLOCK_SIZE, type> block_type;
00030 
00031 void test_typed_block()
00032 {
00033     block_type * a = new block_type;
00034     block_type * b = new block_type;
00035     block_type * A = new block_type[4];
00036     block_type * B = new block_type[1];
00037     block_type * C = NULL;
00038     //C = new block_type[0];
00039     delete a;
00040     a = b;
00041     b = 0;
00042     delete b;
00043     delete a;
00044     delete[] A;
00045     delete[] B;
00046     delete[] C;
00047 }
00048 
00049 void test_aligned_alloc()
00050 {
00051     void * p = stxxl::aligned_alloc<1024>(4096);
00052     void * q = NULL;
00053     void * r = stxxl::aligned_alloc<1024>(4096, 42);
00054     stxxl::aligned_dealloc<1024>(p);
00055     stxxl::aligned_dealloc<1024>(q);
00056     stxxl::aligned_dealloc<1024>(r);
00057 }
00058 
00059 void test_typed_block_vector()
00060 {
00061     std::vector<block_type> v1(2);
00062     std::vector<block_type, stxxl::new_alloc<block_type> > v2(2);
00063 }
00064 
00065 int main()
00066 {
00067     try {
00068         test_typed_block();
00069         test_aligned_alloc();
00070         test_typed_block_vector();
00071     } catch (std::exception e) {
00072         STXXL_MSG("OOPS: " << e.what());
00073         return 1;
00074     } catch (char const * c) {
00075         STXXL_MSG("OOPS: " << c);
00076         return 1;
00077     }
00078 }
00079 // vim: et:ts=4:sw=4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines