commit | author | age
|
23d807
|
1 |
#include<stdlib.h> |
SP |
2 |
#include<unistd.h> |
|
3 |
#include"general.h" |
|
4 |
#include"vesicle.h" |
|
5 |
#include "memory.h" |
|
6 |
|
|
7 |
ts_bool init_memory_block(ts_memory *mem){ |
|
8 |
/* calculate number of bonds, triangles */ |
|
9 |
ts_uint nbonds=3*(mem->vertex_no-2); |
|
10 |
ts_uint ntria=2*(mem->vertex_no-2); |
|
11 |
ts_uint ncells=mem->ncmax[0]*mem->ncmax[1]*mem->ncmax[2]; |
|
12 |
|
|
13 |
ts_uint memsize=sizeof(ts_vesicle)+ |
|
14 |
sizeof(ts_vertex_list)+ sizeof(ts_bond_list)+ sizeof(ts_triangle_list) + |
|
15 |
sizeof(ts_cell_list) + |
|
16 |
mem->vertex_no*(sizeof(ts_vertex)+sizeof(ts_vertex *)) + |
|
17 |
nbonds*(sizeof(ts_bond)+sizeof(ts_bond *))+ |
|
18 |
ntria*(sizeof(ts_triangle)+ sizeof(ts_triangle *))+ |
|
19 |
ncells*(sizeof(ts_cell)+ sizeof(ts_cell *))+ |
|
20 |
MAX_VTXNEIGH*mem->vertex_no*sizeof(ts_vertex *)+ |
|
21 |
MAX_TRISTAR*mem->vertex_no*sizeof(ts_triangle *)+ |
|
22 |
MAX_VTXNEIGH*mem->vertex_no*sizeof(ts_bond *)+ |
|
23 |
3*ntria*sizeof(ts_triangle *)+ |
|
24 |
MAX_CELL_OCCUPANCY*ncells*sizeof(ts_vertex *); |
|
25 |
/* here add size of memory for additional structures!!! */ |
|
26 |
printf("The page size for this system is %ld bytes.\n", |
|
27 |
sysconf(_SC_PAGESIZE)); /* _SC_PAGE_SIZE is OK too. */ |
|
28 |
|
|
29 |
printf("We need to initialize %d B of memory to hold info about vesicle\n",memsize); |
|
30 |
|
|
31 |
void *ptr=calloc(1,memsize); |
|
32 |
|
|
33 |
if(ptr==NULL) fatal("Couldn't initialize memory block in memory.c", TS_ERR_MEM_ALLOC); |
|
34 |
|
|
35 |
/*initialize pointers */ |
|
36 |
void *rptr=ptr; |
|
37 |
//Vesicle and basic lists |
|
38 |
mem->vesicle=(ts_vesicle *)rptr; |
|
39 |
rptr+=sizeof(ts_vesicle); |
|
40 |
mem->vlist=(ts_vertex_list *)rptr; |
|
41 |
rptr+=sizeof(ts_vertex_list); |
|
42 |
mem->blist=(ts_bond_list *)rptr; |
|
43 |
rptr+=sizeof(ts_bond_list); |
|
44 |
mem->tlist=(ts_triangle_list *)rptr; |
|
45 |
rptr+=sizeof(ts_triangle_list); |
|
46 |
mem->clist=(ts_cell_list *)rptr; |
|
47 |
rptr+=sizeof(ts_cell_list); |
|
48 |
|
|
49 |
//Vertex related memory |
|
50 |
mem->vtx_ptr=(ts_vertex **)rptr; |
|
51 |
rptr+=mem->vertex_no*sizeof(ts_vertex *); |
|
52 |
mem->vtx=(ts_vertex *)rptr; |
|
53 |
rptr+=mem->vertex_no*sizeof(ts_vertex); |
|
54 |
mem->vtx_neighbours_ptr=(ts_vertex **)rptr; |
|
55 |
rptr+=mem->vertex_no*MAX_VTXNEIGH*sizeof(ts_vertex *); |
|
56 |
mem->tristar=(ts_triangle **)rptr; |
|
57 |
rptr+=mem->vertex_no*MAX_TRISTAR*sizeof(ts_triangle *); |
|
58 |
mem->vtx_neighbond=(ts_bond **)rptr; |
|
59 |
rptr+=mem->vertex_no*MAX_VTXNEIGH*sizeof(ts_bond *); |
|
60 |
|
|
61 |
|
|
62 |
//Bond related memory |
|
63 |
mem->bond_ptr=(ts_bond **)rptr; |
|
64 |
rptr+=nbonds*sizeof(ts_bond *); |
|
65 |
mem->bond=(ts_bond *)rptr; |
|
66 |
rptr+=nbonds*sizeof(ts_bond); |
|
67 |
|
|
68 |
|
|
69 |
//Triangle related memory |
|
70 |
mem->tria_ptr=(ts_triangle **)rptr; |
|
71 |
rptr+=ntria*sizeof(ts_triangle *); |
|
72 |
mem->tria=(ts_triangle *)rptr; |
|
73 |
rptr+=ntria*sizeof(ts_triangle); |
|
74 |
mem->trianeigh=(ts_triangle **)rptr; |
|
75 |
rptr+=ntria*3*sizeof(ts_triangle *); |
|
76 |
|
|
77 |
//Cell related memory |
|
78 |
mem->cell_ptr=(ts_cell **)rptr; |
|
79 |
rptr+=ncells*sizeof(ts_cell *); |
|
80 |
mem->cell=(ts_cell *)rptr; |
|
81 |
rptr+=ncells*sizeof(ts_cell); |
|
82 |
mem->cell_ocupancy=(ts_vertex **)rptr; |
|
83 |
rptr+= MAX_CELL_OCCUPANCY*ncells*sizeof(ts_vertex *); |
|
84 |
printf("Ptr diff in b=%ld\n",(rptr-ptr)); |
|
85 |
|
|
86 |
return TS_SUCCESS; |
|
87 |
} |