/* px_free -- returns PERM & asoociated memory back to memory heap */ extern int px_free(PERM *px) { if ( px==(PERM *)NULL || (int)(px->size) < 0 ) /* don't trust it */ return (-1); if ( px->pe == (u_int *)NULL ) { if (mem_info_is_on()) { mem_bytes(TYPE_PERM,sizeof(PERM),0); mem_numvar(TYPE_PERM,-1); } free((char *)px); } else { if (mem_info_is_on()) { mem_bytes(TYPE_PERM,sizeof(PERM)+px->max_size*sizeof(u_int),0); mem_numvar(TYPE_PERM,-1); } free((char *)px->pe); free((char *)px); } return (0); }
/* v_free -- returns VEC & asoociated memory back to memory heap */ extern int v_free(VEC *vec) { if ( vec==(VEC *)NULL || (int)(vec->dim) < 0 ) /* don't trust it */ return (-1); if ( vec->ve == (Real *)NULL ) { if (mem_info_is_on()) { mem_bytes(TYPE_VEC,sizeof(VEC),0); mem_numvar(TYPE_VEC,-1); } free((char *)vec); } else { if (mem_info_is_on()) { mem_bytes(TYPE_VEC,sizeof(VEC)+vec->max_dim*sizeof(Real),0); mem_numvar(TYPE_VEC,-1); } free((char *)vec->ve); free((char *)vec); } return (0); }
int zv_free(ZVEC *vec) #endif { if ( vec==(ZVEC *)NULL || (int)(vec->dim) < 0 ) /* don't trust it */ return (-1); if ( vec->ve == (complex *)NULL ) { if (mem_info_is_on()) { mem_bytes(TYPE_ZVEC,sizeof(ZVEC),0); mem_numvar(TYPE_ZVEC,-1); } free((char *)vec); } else { if (mem_info_is_on()) { mem_bytes(TYPE_ZVEC,vec->max_dim*sizeof(complex)+ sizeof(ZVEC),0); mem_numvar(TYPE_ZVEC,-1); } free((char *)vec->ve); free((char *)vec); } return (0); }
/* px_get -- gets a PERM of given 'size' by dynamic memory allocation -- Note: initialized to the identity permutation */ extern PERM *px_get(int size) { PERM *permute; int i; if (size < 0) error(E_NEG,"px_get"); if ((permute=NEW(PERM)) == (PERM *)NULL ) error(E_MEM,"px_get"); else if (mem_info_is_on()) { mem_bytes(TYPE_PERM,0,sizeof(PERM)); mem_numvar(TYPE_PERM,1); } permute->size = permute->max_size = size; if ((permute->pe = NEW_A(size,u_int)) == (u_int *)NULL ) error(E_MEM,"px_get"); else if (mem_info_is_on()) { mem_bytes(TYPE_PERM,0,size*sizeof(u_int)); } for ( i=0; i<size; i++ ) permute->pe[i] = i; return (permute); }
/* v_get -- gets a VEC of dimension 'dim' -- Note: initialized to zero */ extern VEC *v_get(int size) { VEC *vector; if (size < 0) error(E_NEG,"v_get"); if ((vector=NEW(VEC)) == (VEC *)NULL ) error(E_MEM,"v_get"); else if (mem_info_is_on()) { mem_bytes(TYPE_VEC,0,sizeof(VEC)); mem_numvar(TYPE_VEC,1); } vector->dim = vector->max_dim = size; if ((vector->ve=NEW_A(size,Real)) == (Real *)NULL ) { free(vector); error(E_MEM,"v_get"); } else if (mem_info_is_on()) { mem_bytes(TYPE_VEC,0,size*sizeof(Real)); } return (vector); }
ZVEC *zv_get(int size) #endif { ZVEC *vector; if (size < 0) error(E_NEG,"zv_get"); if ((vector=NEW(ZVEC)) == (ZVEC *)NULL ) error(E_MEM,"zv_get"); else if (mem_info_is_on()) { mem_bytes(TYPE_ZVEC,0,sizeof(ZVEC)); mem_numvar(TYPE_ZVEC,1); } vector->dim = vector->max_dim = size; if ((vector->ve=NEW_A(size,complex)) == (complex *)NULL ) { free(vector); error(E_MEM,"zv_get"); } else if (mem_info_is_on()) { mem_bytes(TYPE_ZVEC,0,size*sizeof(complex)); } return (vector); }
ZMAT *zm_get(int m, int n) #endif { ZMAT *matrix; unsigned int i; if (m < 0 || n < 0) error(E_NEG, "zm_get"); if ((matrix = NEW(ZMAT)) == (ZMAT *) NULL) error(E_MEM, "zm_get"); else if (mem_info_is_on()) { mem_bytes(TYPE_ZMAT, 0, sizeof(ZMAT)); mem_numvar(TYPE_ZMAT, 1); } matrix->m = m; matrix->n = matrix->max_n = n; matrix->max_m = m; matrix->max_size = m * n; #ifndef SEGMENTED if ((matrix->base = NEW_A(m * n, complex)) == (complex *) NULL) { free(matrix); error(E_MEM, "zm_get"); } else if (mem_info_is_on()) { mem_bytes(TYPE_ZMAT, 0, m * n * sizeof(complex)); } #else matrix->base = (complex *)NULL; #endif if ((matrix->me = (complex **) calloc(m, sizeof(complex *))) == (complex **) NULL) { free(matrix->base); free(matrix); error(E_MEM, "zm_get"); } else if (mem_info_is_on()) { mem_bytes(TYPE_ZMAT, 0, m * sizeof(complex *)); } #ifndef SEGMENTED /* set up pointers */ for (i = 0; i < m; i++) matrix->me[i] = &(matrix->base[i * n]); #else for ( i = 0; i < m; i++ ) if ( (matrix->me[i]=NEW_A(n,complex)) == (complex *)NULL ) error(E_MEM,"zm_get"); else if (mem_info_is_on()) { mem_bytes(TYPE_ZMAT,0,n*sizeof(complex)); } #endif return (matrix); }
int bd_free(BAND *A) #endif { if ( A == (BAND *)NULL || A->lb < 0 || A->ub < 0 ) /* don't trust it */ return (-1); if (A->mat) m_free(A->mat); if (mem_info_is_on()) { mem_bytes(TYPE_BAND,sizeof(BAND),0); mem_numvar(TYPE_BAND,-1); } free((char *)A); return 0; }
int zm_free(ZMAT *mat) #endif { #ifdef SEGMENTED int i; #endif if ( mat==(ZMAT *)NULL || (int)(mat->m) < 0 || (int)(mat->n) < 0 ) /* don't trust it */ return (-1); #ifndef SEGMENTED if ( mat->base != (complex *)NULL ) { if (mem_info_is_on()) { mem_bytes(TYPE_ZMAT,mat->max_m*mat->max_n*sizeof(complex),0); } free((char *)(mat->base)); } #else for ( i = 0; i < mat->max_m; i++ ) if ( mat->me[i] != (complex *)NULL ) { if (mem_info_is_on()) { mem_bytes(TYPE_ZMAT,mat->max_n*sizeof(complex),0); } free((char *)(mat->me[i])); } #endif if ( mat->me != (complex **)NULL ) { if (mem_info_is_on()) { mem_bytes(TYPE_ZMAT,mat->max_m*sizeof(complex *),0); } free((char *)(mat->me)); } if (mem_info_is_on()) { mem_bytes(TYPE_ZMAT,sizeof(ZMAT),0); mem_numvar(TYPE_ZMAT,-1); } free((char *)mat); return (0); }
BAND *bd_get(int lb, int ub, int n) #endif { BAND *A; if (lb < 0 || ub < 0 || n <= 0) error(E_NEG,"bd_get"); if ((A = NEW(BAND)) == (BAND *)NULL) error(E_MEM,"bd_get"); else if (mem_info_is_on()) { mem_bytes(TYPE_BAND,0,sizeof(BAND)); mem_numvar(TYPE_BAND,1); } lb = A->lb = min(n-1,lb); ub = A->ub = min(n-1,ub); A->mat = m_get(lb+ub+1,n); return A; }