if (*n < 0) *opt = NULL;
else {
*opt = nlopt_create((nlopt_algorithm) *alg, (unsigned) *n);
- (*opt)->free_f_data = 1;
+ nlopt_set_free_f_data(*opt, 1);
}
}
d->f = f;
d->f_data = f_data;
*ret = (int) nlopt_set_min_objective(*opt, f77_func_wrap, d);
- /* FIXME: memory leak in nlopt_destroy */
}
void F77_(nlo_set_max_objective,NLO_SET_MAX_OBJECTIVE)(
NLOPT_EXTERN nlopt_result nlopt_get_initial_step(const nlopt_opt opt,
const double *x, double *dx);
+/* set to 1: nlopt_destroy should call free() on all of the f_data pointers
+ (for the objective, constraints, etcetera) ... mainly for internal use */
+NLOPT_EXTERN nlopt_result nlopt_set_free_f_data(nlopt_opt opt, int val);
+NLOPT_EXTERN int nlopt_get_free_f_data(nlopt_opt opt);
+
/*************************** DEPRECATED API **************************/
/* The new "object-oriented" API is preferred, since it allows us to
gracefully add new features and algorithm-specific options in a
{
if (opt) {
opt->f = f; opt->f_data = f_data;
- if (f_data) opt->free_f_data = 0;
opt->maximize = 0;
if (nlopt_isinf(opt->stopval) && opt->stopval > 0)
opt->stopval = -HUGE_VAL; /* switch default from max to min */
{
if (opt) {
opt->f = f; opt->f_data = f_data;
- if (f_data) opt->free_f_data = 0;
opt->maximize = 1;
if (nlopt_isinf(opt->stopval) && opt->stopval < 0)
opt->stopval = +HUGE_VAL; /* switch default from min to max */
&& opt->algorithm != NLOPT_GN_ORIG_DIRECT
&& opt->algorithm != NLOPT_GN_ORIG_DIRECT_L)
return NLOPT_INVALID_ARGS;
- if (fc_data) opt->free_f_data = 0;
return add_constraint(&opt->m, &opt->m_alloc, &opt->fc,
fc, fc_data, tol);
}
/* equality constraints (h(x) = 0) only via some algorithms */
if (!AUGLAG_ALG(opt->algorithm) && opt->algorithm != NLOPT_GN_ISRES)
return NLOPT_INVALID_ARGS;
- if (h_data) opt->free_f_data = 0;
return add_constraint(&opt->p, &opt->p_alloc, &opt->h,
h, h_data, tol);
}
}
/*************************************************************************/
+
+GETSET(free_f_data, int, free_f_data)
+
+/*************************************************************************/