本文整理汇总了C++中free_array函数的典型用法代码示例。如果您正苦于以下问题:C++ free_array函数的具体用法?C++ free_array怎么用?C++ free_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了free_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f_tokenize
/*! @decl array(array(string)|string) tokenize(string code)
*!
*! Tokenize a string of Pike tokens.
*!
*! @returns
*! Returns an array with Pike-level tokens and the remainder (a
*! partial token), if any.
*/
static void f_tokenize( INT32 args )
{
struct array *res;
struct pike_string *left_s = NULL; /* Make gcc happy. */
struct pike_string *data;
int left;
ONERROR tmp;
get_all_args("tokenize", args, "%W", &data);
if(!data->len)
{
pop_n_elems(args);
push_empty_array();
push_empty_string();
f_aggregate(2);
return;
}
res = allocate_array_no_init( 0, 128 );
SET_ONERROR(tmp, do_free_arrayptr, &res);
switch(data->size_shift)
{
case 0:
left = tokenize0(&res, STR0(data), data->len);
left_s = make_shared_binary_string0(STR0(data)+left, data->len-left);
break;
case 1:
left = tokenize1(&res, STR1(data), data->len);
left_s = make_shared_binary_string1(STR1(data)+left, data->len-left);
break;
case 2:
left = tokenize2(&res,STR2(data), data->len);
left_s = make_shared_binary_string2(STR2(data)+left, data->len-left);
break;
#ifdef PIKE_DEBUG
default:
Pike_error("Unknown shift size %d.\n", data->size_shift);
#endif
}
UNSET_ONERROR(tmp);
pop_n_elems(args);
if (!res->size) {
free_array(res);
push_empty_array();
}
else
push_array(res);
push_string( left_s );
f_aggregate( 2 );
}
示例2: main
int main(int argc, const char * argv[]) {
char filename[MAX_LENGTH];
node_t * nodes[MAX_NODES];
FILE * file;
int count;
int i;
//check that there is correct number of arguments
if (argc != 2) {
printf("graphexec requires 2 arguments.\n");
return -1;
}
//open file and check that it was sucessful
file = fopen(argv[1], "r");
if (!file) {
printf("The file specified does not exist or could not be opened.\n");
}
//if things check out, proceed to read and process file
else {
count = read_file(file, nodes, MAX_NODES);
bool finished;
while (!finished) {
finished = true;
determine_eligible(nodes, count);
//iterate through and run nodes that are marked READY
for (i = 0; i < count; i++) {
if (nodes[i]->status != FINISHED) {
finished = false;
if (nodes[i]->status == READY) {
printf("Node %i Status: Running", i);
if(run_node(nodes[i]) == FINISHED &&
run_node(nodes[i]) != -1) {
printf(" >> Finished!\n");
} else
perror("Error running node");
}
}
}
}
//cleanup
free_array(nodes, count);
if (fclose(file) == -1)
perror("Failed to close file");
}
return 0;
}
示例3: mread_set_bg_source
/*
* Set the background source to be used for pseudocounts.
* The background is resolved by the following rules:
* - If source is:
* null or "--nrdb--" use nrdb frequencies
* "--uniform--" use uniform frequencies
* "motif-file" use frequencies in motif file
* file name read frequencies from bg file
*/
void mread_set_bg_source(MREAD_T *mread, const char *source) {
// clean up old bg
if (mread->other_bg != NULL) free_array(mread->other_bg);
mread->other_bg = NULL;
if (mread->other_bg_src != NULL) free(mread->other_bg_src);
mread->other_bg_src = NULL;
// copy the passed source
if (source != NULL) {
mread->other_bg_src = strdup(source);
}
// check if we've chosen a parser already
if (mread->success) set_pseudo_bg(mread);
}
示例4: shrink
/*
shrink(double** A, double t, int M) applies the shrink operator on A with thresholding parameter t.
The idea is to compute the SVD of A, A=U*S*V, then create the matrix B
B = U * S2 * V,
where S2_{i,i} = S_{i,i} if ((S_{i,i}-)*t>0) and
S2_{i,i} = 0 otherwise.
Then it returns B.
*/
double* shrink(double* A, double tau, int nrows, int ncols, char method){
int i;
int info = 0;
char JOBU = 'A';
char JOBVT = 'A';
int LWORK = fmax(fmax(1,3*fmin(nrows,ncols)+fmax(nrows,ncols)),5*fmin(nrows,ncols));
double* WORK = alloc_array(1, LWORK);
double* U = alloc_array(nrows, nrows);
double* VT = alloc_array(ncols, ncols);
double* S = alloc_array(fmin(nrows,ncols), fmin(nrows, ncols));
int min_dim = fmin(nrows,ncols);
dgesvd_(&JOBU, &JOBVT, &nrows, &ncols, A, &nrows, S, U, &nrows, VT, &ncols, WORK, &LWORK, &info);
if( method == 'S' ){
for( i = 0; i < min_dim; i++){
S[i] = fmax(0.0, S[i] - tau);
}
}
else if( method == 'P' ){
#pragma omp parallel for
for(i=0; i < min_dim;i++){
S[i] = fmax(0.0, S[i] - tau);
}
}
double* C = alloc_array_z(nrows,ncols);
//C = mm(mm(U, nrows, nrows, 't', diag(S,nrows, ncols), nrows, ncols, 'n'), nrows, ncols, 'n', VT, ncols, ncols, 't');
C = mm(mm(VT, ncols, ncols, 'n', diag(S,ncols, nrows), ncols, nrows, 'n'), ncols, nrows, 'n', U, nrows, nrows, 'n');
//free_array(A);
free_array(WORK);
free_array(U);
free_array(VT);
free_array(S);
return C;
}
示例5: mread_set_background
/*
* Set the background to be used for pseudocounts.
*/
void mread_set_background(MREAD_T *mread, const ARRAY_T *bg) {
// clean up old bg
if (mread->other_bg != NULL) free_array(mread->other_bg);
mread->other_bg = NULL;
if (mread->other_bg_src != NULL) free(mread->other_bg_src);
mread->other_bg_src = NULL;
// copy the passed background
if (bg != NULL) {
mread->other_bg = allocate_array(get_array_length(bg));
copy_array(bg, mread->other_bg);
}
// check if we've chosen a parser already
if (mread->success) set_pseudo_bg(mread);
}
示例6: circuit_model
int circuit_model(graph_t * g, int nG)
{
double **Gm;
double **Gm_inv;
int rv;
long i, j;
node_t *v;
edge_t *e;
Gm = new_array(nG, nG, 0.0);
Gm_inv = new_array(nG, nG, 0.0);
/* set non-diagonal entries */
for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
for (e = agfstedge(g, v); e; e = agnxtedge(g, e, v)) {
i = AGID(agtail(e));
j = AGID(aghead(e));
if (i == j)
continue;
/* conductance is 1/resistance */
Gm[i][j] = Gm[j][i] = -1.0 / ED_dist(e); /* negate */
}
}
rv = solveCircuit(nG, Gm, Gm_inv);
if (rv)
for (i = 0; i < nG; i++) {
for (j = 0; j < nG; j++) {
GD_dist(g)[i][j] =
Gm_inv[i][i] + Gm_inv[j][j] - 2.0 * Gm_inv[i][j];
}
}
free_array(Gm);
free_array(Gm_inv);
return rv;
}
示例7: getino
// Searches through the device along pathname for target file
// Returns the target file's inode number if found
int getino(int device, const char* pathname)
{
int ino = 0;
char** name = NULL;
if(strcmp(pathname, "/") == 0)
return ROOT_INODE;
name = parse(pathname, "/");
// Absolute or Relative?
if(pathname[0] == '/')
ino = search(root, name[0]); // Absolute: start at root
else
ino = search(running->cwd, name[0]);// Relative: start at cwd
if(ino <= 0)
{
free_array(name);
return DOES_NOT_EXIST;
}
// Continue search
int i = 0;
while(name[++i])
{
if((ino = search(iget(device, ino), name[i])) <= 0)
{
free_array(name);
return DOES_NOT_EXIST;
}
}
free_array(name);
return ino;
}
示例8: free_array
/* CLEANUP */
static void free_array(Meta **array, int size) {
int index;
Meta *meta;
for (index = 0; index < size; index++) {
meta = array[index]; // recursive cleaning
if (meta->children->list)
free_array(meta->children->list,
meta->children->index);
free(meta->measure);
free(meta->children);
free(meta);
}
// free the main object
free(array);
}
示例9: obj_read_mtllib_read_tr
void obj_read_mtllib_read_tr(t_obj *obj, char *line)
{
char **datas;
if (!(datas = ft_strsplit(line, ' ')))
ERROR("ft_strsplit failed");
if (!datas[0] || !datas[1] || datas[2])
ERROR("invalid mtl tr line");
if (!parse_valid_number(datas[1]))
ERROR("invalid mtl tr value");
if (!obj->current_mtl)
ERROR("no current mtl for tr");
obj->current_mtl->mtl.tr = 1 - ft_atod(datas[1]);
free_array(datas);
}
示例10: free_lex_ctxt
void
free_lex_ctxt (lex_ctxt * c)
{
int i;
#if 0
if (c->exit_flag && c->up_ctxt != NULL)
((lex_ctxt *) c->up_ctxt)->exit_flag = 1;
#endif
deref_cell (c->ret_val);
free_array (&c->ctx_vars);
for (i = 0; i < FUNC_NAME_HASH; i++)
{
free_func_chain (c->functions[i]);
}
efree (&c);
}
示例11: main
int main(int argc, char *argv[]) {
int *array = random_gen(ARRAY_SIZE);
printf("\n# ----- Original Data ----- #\n\n");
print_array(array, ARRAY_SIZE);
insertion_int(array, ARRAY_SIZE);
printf("\n# ----- Sorted Data ----- #\n\n");
print_array(array, ARRAY_SIZE);
printf("\n");
free_array(array);
return 0;
}
示例12: cudd_size
/* Use CUDD to compute number of BDD nodes to represent set of functions */
size_t cudd_size(shadow_mgr mgr, set_ptr roots) {
if (!mgr->do_cudd)
return 0;
size_t nele = roots->nelements;
DdNode **croots = calloc_or_fail(nele, sizeof(DdNode *), "cudd_size");
word_t wr;
int i = 0;
set_iterstart(roots);
while (set_iternext(roots, &wr)) {
ref_t r = (ref_t) wr;
DdNode *n = get_ddnode(mgr, r);
croots[i++] = n;
}
int cnt = Cudd_SharingSize(croots, nele);
free_array(croots, nele, sizeof(DdNode *));
return (size_t) cnt;
}
示例13: free_anon_var
static void
free_anon_var(anon_nasl_var* v)
{
if (v == NULL)
return;
switch(v->var_type)
{
case VAR2_STRING:
case VAR2_DATA:
efree(&v->v.v_str.s_val);
break;
case VAR2_ARRAY:
free_array(&v->v.v_arr);
break;
}
efree(&v);
}
示例14: f_fetch_class_member
void f_fetch_class_member() {
int pos = sp->u.number;
array_t *arr;
pos = sp->u.number;
pop_stack();
if( sp->type != T_CLASS )
error( "Argument to fetch_class_member() not a class.\n" );
arr = sp->u.arr;
if( pos < 0 || pos >= arr->size )
error( "Class index out of bounds.\n" );
assign_svalue_no_free( sp, &arr->item[pos] );
free_array( arr );
}
示例15: preload_objects
/* New version used when not in -o mode. The epilog() in master.c is
* supposed to return an array of files (castles in 2.4.5) to load. The array
* returned by apply() will be freed at next call of apply(), which means that
* the ref count has to be incremented to protect against deallocation.
*
* The master object is asked to do the actual loading.
*/
void preload_objects (int eflag)
{
VOLATILE array_t *prefiles;
svalue_t *ret;
VOLATILE int ix;
error_context_t econ;
save_context(&econ);
if (SETJMP(econ.context)) {
restore_context(&econ);
pop_context(&econ);
return;
}
push_number(eflag);
ret = apply_master_ob(APPLY_EPILOG, 1);
pop_context(&econ);
if ((ret == 0) || (ret == (svalue_t *)-1) || (ret->type != T_ARRAY))
return;
else
prefiles = ret->u.arr;
if ((prefiles == 0) || (prefiles->size < 1))
return;
debug_message("\nLoading preloaded files ...\n");
prefiles->ref++;
ix = 0;
/* in case of an error, effectively do a 'continue' */
save_context(&econ);
if (SETJMP(econ.context)) {
restore_context(&econ);
ix++;
}
for ( ; ix < prefiles->size; ix++) {
if (prefiles->item[ix].type != T_STRING)
continue;
set_eval(max_cost);
push_svalue(((array_t *)prefiles)->item + ix);
(void) apply_master_ob(APPLY_PRELOAD, 1);
}
free_array((array_t *)prefiles);
pop_context(&econ);
} /* preload_objects() */