#include #include #include"general.h" #include"vesicle.h" #include "memory.h" ts_bool init_memory_block(ts_memory *mem){ /* calculate number of bonds, triangles */ ts_uint nbonds=3*(mem->vertex_no-2); ts_uint ntria=2*(mem->vertex_no-2); ts_uint ncells=mem->ncmax[0]*mem->ncmax[1]*mem->ncmax[2]; ts_uint memsize=sizeof(ts_vesicle)+ sizeof(ts_vertex_list)+ sizeof(ts_bond_list)+ sizeof(ts_triangle_list) + sizeof(ts_cell_list) + mem->vertex_no*(sizeof(ts_vertex)+sizeof(ts_vertex *)) + nbonds*(sizeof(ts_bond)+sizeof(ts_bond *))+ ntria*(sizeof(ts_triangle)+ sizeof(ts_triangle *))+ ncells*(sizeof(ts_cell)+ sizeof(ts_cell *))+ MAX_VTXNEIGH*mem->vertex_no*sizeof(ts_vertex *)+ MAX_TRISTAR*mem->vertex_no*sizeof(ts_triangle *)+ MAX_VTXNEIGH*mem->vertex_no*sizeof(ts_bond *)+ 3*ntria*sizeof(ts_triangle *)+ MAX_CELL_OCCUPANCY*ncells*sizeof(ts_vertex *); /* here add size of memory for additional structures!!! */ printf("The page size for this system is %ld bytes.\n", sysconf(_SC_PAGESIZE)); /* _SC_PAGE_SIZE is OK too. */ printf("We need to initialize %d B of memory to hold info about vesicle\n",memsize); void *ptr=calloc(1,memsize); if(ptr==NULL) fatal("Couldn't initialize memory block in memory.c", TS_ERR_MEM_ALLOC); /*initialize pointers */ void *rptr=ptr; //Vesicle and basic lists mem->vesicle=(ts_vesicle *)rptr; rptr+=sizeof(ts_vesicle); mem->vlist=(ts_vertex_list *)rptr; rptr+=sizeof(ts_vertex_list); mem->blist=(ts_bond_list *)rptr; rptr+=sizeof(ts_bond_list); mem->tlist=(ts_triangle_list *)rptr; rptr+=sizeof(ts_triangle_list); mem->clist=(ts_cell_list *)rptr; rptr+=sizeof(ts_cell_list); //Vertex related memory mem->vtx_ptr=(ts_vertex **)rptr; rptr+=mem->vertex_no*sizeof(ts_vertex *); mem->vtx=(ts_vertex *)rptr; rptr+=mem->vertex_no*sizeof(ts_vertex); mem->vtx_neighbours_ptr=(ts_vertex **)rptr; rptr+=mem->vertex_no*MAX_VTXNEIGH*sizeof(ts_vertex *); mem->tristar=(ts_triangle **)rptr; rptr+=mem->vertex_no*MAX_TRISTAR*sizeof(ts_triangle *); mem->vtx_neighbond=(ts_bond **)rptr; rptr+=mem->vertex_no*MAX_VTXNEIGH*sizeof(ts_bond *); //Bond related memory mem->bond_ptr=(ts_bond **)rptr; rptr+=nbonds*sizeof(ts_bond *); mem->bond=(ts_bond *)rptr; rptr+=nbonds*sizeof(ts_bond); //Triangle related memory mem->tria_ptr=(ts_triangle **)rptr; rptr+=ntria*sizeof(ts_triangle *); mem->tria=(ts_triangle *)rptr; rptr+=ntria*sizeof(ts_triangle); mem->trianeigh=(ts_triangle **)rptr; rptr+=ntria*3*sizeof(ts_triangle *); //Cell related memory mem->cell_ptr=(ts_cell **)rptr; rptr+=ncells*sizeof(ts_cell *); mem->cell=(ts_cell *)rptr; rptr+=ncells*sizeof(ts_cell); mem->cell_ocupancy=(ts_vertex **)rptr; rptr+= MAX_CELL_OCCUPANCY*ncells*sizeof(ts_vertex *); printf("Ptr diff in b=%ld\n",(rptr-ptr)); return TS_SUCCESS; }