source: trunk/test_more/track_new_del.cpp @ 3757

Last change on this file since 3757 was 3757, checked in by bradbell, 4 years ago

merge to branch: trunk
from repository: https://github.com/coin-or/CppAD
start hash code: af6d293b6d7c5f0e00b361108403b4200215a7a7
end hash code: aec9ede58726ce1a40825eac63d4d8f7cb40bfba

commit aec9ede58726ce1a40825eac63d4d8f7cb40bfba
Author: Brad Bell <bradbell@…>
Date: Sun Nov 29 21:24:17 2015 -0800

Move omh/libaray to omh/utility becasue it corresponds to cppad/utility.

commit 17b6e02f29dcc2a1ab2d2e6980a979374e73e19e
Author: Brad Bell <bradbell@…>
Date: Sun Nov 29 19:03:22 2015 -0800

Batch edit the entire souce directory using the script

bin/batch_edit.sh

  1. With a few exceptions, move cppad/*.hpp to cppad/utility/*.hpp
  2. Change include gaurd from CPPAD_<NAME>_INCLUDED to CPPAD_<NAME>_HPP
  3. Make the source code control $Id$ commands more uniform.
  4. Remove invisible white space
  5. Create utility.hpp (includes entire utilty directory)

commit 4a8fbe249f97116cac86583a7d9bf596dbb06473
Author: Brad Bell <bradbell@…>
Date: Sun Nov 29 18:12:50 2015 -0800

new version that passes bin/check_all.sh

commit f041069fe3e24d68133f829353f7200cf2c299ed
Author: Brad Bell <bradbell@…>
Date: Sun Nov 29 14:27:08 2015 -0800

pases bin/check_all.sh

commit 32ac61696305b7625938d4c488203cdcc19f36dc
Author: Brad Bell <bradbell@…>
Date: Sun Nov 29 06:13:56 2015 -0800

passed bin/check_all.sh

  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1// $Id: track_new_del.cpp 3757 2015-11-30 12:03:07Z bradbell $
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
4
5CppAD is distributed under multiple licenses. This distribution is under
6the terms of the
7                    Eclipse Public License Version 1.0.
8
9A copy of this license is included in the COPYING file of this distribution.
10Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
11-------------------------------------------------------------------------- */
12
13/*
14$begin TrackNewDel.cpp$$
15
16$section Tracking Use of New and Delete: Example and Test$$
17$mindex delete$$
18
19
20
21$code
22$verbatim%test_more/track_new_del.cpp%0%// BEGIN C++%// END C++%1%$$
23$$
24
25$end
26*/
27// BEGIN C++
28
29# include <cppad/utility/track_new_del.hpp>
30
31bool track_new_del(void)
32{       bool ok = true;
33
34        // initial count
35        size_t count = CPPAD_TRACK_COUNT();
36
37        // allocate an array of lenght 5
38        double *ptr = CPPAD_NULL;
39        size_t  newlen = 5;
40        ptr = CPPAD_TRACK_NEW_VEC(newlen, ptr);
41
42        // copy data into the array
43        size_t ncopy = newlen;
44        size_t i;
45        for(i = 0; i < ncopy; i++)
46                ptr[i] = double(i);
47
48        // extend the buffer to be lenght 10
49        newlen = 10;
50        ptr    = CPPAD_TRACK_EXTEND(newlen, ncopy, ptr);
51
52        // copy data into the new part of the array
53        for(i = ncopy; i < newlen; i++)
54                ptr[i] = double(i);
55
56        // check the values in the array
57        for(i = 0; i < newlen; i++)
58                ok &= (ptr[i] == double(i));
59
60        // free the memory allocated since previous call to TrackCount
61        CPPAD_TRACK_DEL_VEC(ptr);
62
63        // check for memory leak
64        ok &= (count == CPPAD_TRACK_COUNT());
65
66        return ok;
67}
68
69// END C++
Note: See TracBrowser for help on using the repository browser.