Ticket #10954: split_std_deque.cpp

File split_std_deque.cpp, 1.5 KB (added by split_std_deque, 8 years ago)

example causing the memory leak

Line 
1#include <cstdlib>
2#include <iostream>
3#include <boost/spirit/home/qi.hpp>
4#include <boost/spirit/home/support.hpp>
5#include <boost/spirit/home/support/multi_pass.hpp>
6#include <boost/spirit/home/support/iterators/detail/functor_input_policy.hpp>
7
8
9class iterate_rnd {
10private:
11 size_t limit_;
12public:
13 typedef char result_type;
14
15 static result_type eof;
16
17 iterate_rnd() : limit_(104857600) {}
18 iterate_rnd(size_t limit) : limit_(limit) {}
19
20 result_type operator()() {
21 if (limit_ == 0) return eof;
22 limit_--;
23 return rand() & 0x7F;
24 }
25};
26
27
28iterate_rnd::result_type iterate_rnd::eof = iterate_rnd::result_type(-1);
29
30
31using namespace boost::spirit;
32
33
34typedef multi_pass<
35 iterate_rnd,
36 iterator_policies::default_policy<
37 iterator_policies::ref_counted,
38 iterator_policies::no_check,
39 iterator_policies::functor_input,
40 iterator_policies::split_std_deque
41 >
42> functor_multi_pass_type;
43
44
45int main() {
46 functor_multi_pass_type first = functor_multi_pass_type(iterate_rnd());
47 functor_multi_pass_type last;
48 std::string input;
49
50 {
51 functor_multi_pass_type copy(first);
52 while (first != last) {
53 ++first;
54 }
55 std::cout << "Iterator offset at this point is " << std::distance(copy, first) << std::endl;
56 }
57
58 first.clear_queue();
59 /* only one reference to the shared memory object is
60 * left, but no memory reset is triggered within the iterator */
61 std::cout << "Press enter to exit. Check memory usage at this point.";
62 std::getline(std::cin, input);
63
64 return 0;
65}