source: trunk/test_more/track_new_del.cpp @ 3793

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

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

commit 431e0a227dbfe6172d265d9d79a2b5b258c5bc18
Author: Brad Bell <bradbell@…>
Date: Tue Feb 9 07:41:29 2016 -0700

  1. Change package.sh to automatically update version on (master branch only).
  2. Change version.sh copy to check and change.

commit a14455414810cfe3c3e4bca90090defc2528a353
Author: Brad Bell <bradbell@…>
Date: Tue Feb 9 06:19:54 2016 -0700

Change check_verbatim to check_srcfile
because all but one of the verbatim commands were changed to srcfile commands.


check_include_omh.sh: old check that file names did not change case (for cygwin development).

commit 4ce45b796b57629332ab46d8ae6df94e0a1ed998
Author: Brad Bell <bradbell@…>
Date: Tue Feb 9 06:04:57 2016 -0700

batch_edit.sh to change $verbatim and $codep to $srcfile and $srccode.


det_by_minor.c: remove some invisible white space.

commit 56553b88c9623c30d2222425a9640b95ce4c8281
Author: Brad Bell <bradbell@…>
Date: Mon Feb 8 18:01:49 2016 -0700

check_jenkins.sh: jenkins.sh no longer takes an argument.
jenkins.sh: fix name of script in error message.

commit 3b8a208cfc7e8ef3c928c17eb291aa3b90ff0050
Author: Brad Bell <bradbell@…>
Date: Mon Feb 8 07:57:02 2016 -0700

new_release.sh: track branches in comments, back to master at OK end, first check of response.

commit 442b7cbc45c022776e8257d3c3404dccdd06c420
Author: Brad Bell <bradbell@…>
Date: Mon Feb 8 06:01:11 2016 -0700

  1. Advance to release 20160000.1.
  2. Check using master version of new_release.sh.
  3. Make sure auto-tools version up to date.
  4. Ask user if doing further testing before commiting new release.

commit f7bdd1f48e72feb05d604da63914022809f45c28
Author: Brad Bell <bradbell@…>
Date: Sun Feb 7 07:59:41 2016 -0700

Add shared library version number to cppad_lib; i.e., cppad_lib.yyyy.mmdd.rel

commit a4c716552e3ad05b337aea58b643c9ad1cbcd4ac
Author: Brad Bell <bradbell@…>
Date: Sun Feb 7 05:25:39 2016 -0700

Make cppad_lib libarary conditional on colpack_prefix being specified.

commit 5e8890eb8de8b0cde146a6ed59c391d7c355ff24
Author: Brad Bell <bradbell@…>
Date: Tue Jan 26 10:49:37 2016 -0700

vector.hpp: fix The -> This.

commit e4e5442b069d7b00e197c31616da32eee20460b3
Merge: c4559d5 ed28b89
Author: Brad Bell <bradbell@…>
Date: Tue Jan 26 09:47:58 2016 -0700

Merge pull request #14 from barak/master


fix spelling in description of cppad_profile_flag on cmake command line

commit ed28b899c9fedab52a578aa7dd73818638081fe6
Author: Barak A. Pearlmutter <barak+git@…>
Date: Tue Jan 26 16:24:32 2016 +0000

typo

  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1// $Id: track_new_del.cpp 3788 2016-02-09 15:50:06Z bradbell $
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 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$srcfile%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.