Ejemplo n.º 1
0
/**
 * free the memory used by an mtree
 *
 * @param[in] h handle to mtree to free
 * @param[in] free_surface boolean to indicate whether to free the surface values
 */
void __m_free(H h,int free_surface) {
    int i = h.m->levels;
    while(i--) {
    L *l = _GET_LEVEL(h,i);
    Mindex j = l->nodes;
    if (free_surface) {
        while(j--) {
        N *n = _GET_NODE(h,l,j);
        if (n->flags & TFLAG_ALLOCATED) {
            free(n->surface);
        }
        }
    }
    free(l->nP);
    }
    free(h.m->lP);
    free(h.m);
}
Ejemplo n.º 2
0
// low-level function to add c nodes to given level
/// @todo make this not realloc each time!!
N *__m_add_nodes(H h,L *l,int c) {
    N *n;
    Mindex i = l->nodes;
    if (!i) {
        size_t s = sizeof(N)*c;
        l->nP = malloc(s);
        memset(l->nP,0,s);
        l->nodes = c;
    }
    else {
        //  size_t os = sizeof(N)*l->nodes;
        l->nodes += c;
        size_t ns = sizeof(N)*l->nodes;
        l->nP = realloc(l->nP,ns);
        //  memset(l->nP+ns,0,sizeof(N)*c);
    }
    n = _GET_NODE(h,l,i);
    return n;
}
Ejemplo n.º 3
0
/**
 * free the memory used by an mtree
 *
 * @param[in] h handle to mtree to free
 * @param[in] free_surface boolean to indicate whether to free the surface values
 */
void __m_free(H h,int free_surface) {
    int i = h.m->levels;
    while(i--) {
        L *l = _GET_LEVEL(h,i);
        Mindex j = l->nodes;
        if (free_surface) {
            while(j--) {
                N *n = _GET_NODE(h,l,j);
                if (!(n->flags & TFLAG_REFERENCE)) {
                    if (n->flags & TFLAG_SURFACE_IS_RECEPTOR) raise_error("mtree can't free receptor!");
                    if (n->flags & TFLAG_SURFACE_IS_TREE && !(n->flags & TFLAG_SURFACE_IS_RECEPTOR)) {
                        _m_free(*(H *)n->surface);
                    }
                    if (n->flags & TFLAG_ALLOCATED) {
                        free(n->surface);
                    }
                }
            }
        }
        free(l->nP);
    }
    free(h.m->lP);
    free(h.m);
}