Borderbasix

memory.hpp
Go to the documentation of this file.
1 #ifndef ALREADY_memory
2 #define ALREADY_memory
3 void freeplacemon();
4 template<typename T>
5 void INIT_ELEM(void * ptr, int size)
6 {
7  //cout<<"je passe par l'init"<<endl;
8  for(unsigned i=0;i<(size/(sizeof(T)));i++)
9  new((T*)ptr+i) T;
10 
11 }
12 #if 0
13 template<>
14 void INIT_ELEM<Z<MON_PREMIER, short int> >(void * ptr, int size)
15 {
16  //cout<<"je passe par l'init"<<endl;
17  for(unsigned i=0;i<(size/(sizeof(Z<MON_PREMIER,short int>)));i++)
18  {
20  *((Z<MON_PREMIER,short int> *)ptr+i)=0;
21  }
22 }
23 #endif
24 
25 template<typename T>
26 void CLEAR_ELEM(void * ptr, int size)
27 {
28  for(unsigned int i=0;i<size/(sizeof(T));i++)
29  ((T*)ptr+i)->~T();
30 }
31 //#include"mpaispecial.cc"
32 //#include "mpqspecial.hpp"
33 //#include "mpfspecial.hpp"
34 //#include "mpzspecial.hpp"
35 //#include "modspecial.cpp"
36 
37 //#ifdef NEED_INIT_ELEM
38 template<typename T>
39 inline void * MAC_REV_MALLOC(int size)
40 {
41  //cout<<"c'est celui la "<<endl;
42  void * res;
43  res=malloc(size);
44  INIT_ELEM<T>(res,size);
45  return res;
46 }
47 
48 template<typename T>
49 inline void * MAC_REV_REALLOC(void * ptr,int size,int newsize)
50 {
51  void *res=ptr;
52  if(size<newsize)
53  {
54  res=realloc(ptr,newsize);
55  INIT_ELEM<T>((char*)res+size,newsize-size);
56  }
57  if(size>newsize)
58  {
59  CLEAR_ELEM<T>((char*)ptr+newsize,size-newsize);
60  res=realloc(ptr,newsize);
61  }
62  return res;
63 }
64 template<typename T>
65 inline void MAC_REV_FREE(void * ptr,int size)
66 {
67  if(size>0)
68  CLEAR_ELEM<T>(ptr,size);
69  free(ptr);
70 }
71 #if 0
72 template<>
73 void INIT_ELEM<Mon>(void *ptr,int size)
74 {
75  typedef Mon::coeff_t coeff;
76  int tmp=size/sizeof(Mon);
77  for(int i=0;i<tmp;i++)
78  INIT_ELEM<coeff>(&(((Mon*)ptr+i)->coeff),sizeof(coeff));
79 }
80 
81 template<>
82 void CLEAR_ELEM<mon>(void *ptr,int size)
83 {
84  typedef mon::coeff_t coeff;
85  int tmp=size/sizeof(mon);
86  for(int i=0;i<tmp;i++)
87  CLEAR_ELEM<coeff>(&(((mon*)ptr)+i)->coeff,sizeof(coeff));
88 }
89 #endif
90 #if 0
91 template<typename T>
92 inline void * MAC_REV_MALLOC(int size)
93 {
94  void * res;
95  res=malloc(size);
96  return res;
97 }
98 
99 template<typename T>
100 inline void * MAC_REV_REALLOC(void * ptr,int size,int newsize)
101 {
102  void * res;
103  res=realloc(ptr,newsize);
104  return res;
105 }
106 template<typename T>
107 inline void MAC_REV_FREE(void * ptr,int size)
108 {
109  free(ptr);
110  }
111 template<>
112 inline void * MAC_REV_MALLOC<mon>(int size)
113 {
114  void * res;
115  res=malloc(size);
116  for(int i=0;i<size/sizeof(mon);i++)
117  new((mon *)res+i) mon;
118  return res;
119 }
120 
121 template<>
122 inline void * MAC_REV_REALLOC<mon>(void * ptr,int size,int newsize)
123 {
124  void *res=ptr;
125  int tmp=size/sizeof(mon);
126  if(size<newsize)
127  {
128  res=realloc(ptr,newsize);
129  for(int i=0;i<(newsize-size)/sizeof(mon);i++)
130  new((mon*)res+tmp+i) mon;
131  }
132  if(size>newsize)
133  {
134  for(int i=0;i<(size-newsize)/sizeof(mon);i++)
135  ((mon*)res+tmp+i)->~mon();
136  res=realloc(ptr,newsize);
137  }
138  return res;
139 }
140 
141 template<>
142 inline void MAC_REV_FREE<mon>(void * ptr,int size)
143 {
144  for(int i=0;i<(size)/sizeof(mon);i++)
145  ((mon*)ptr+i)->~mon();
146  free(ptr);
147  }
148 
149 #endif
150 
151 template<typename typdump, typename Base>
152 /*#ifdef unimul
153 #ifdef uninf
154 void sweep(typdump &dump,Base &b,int **multiple,void**nfmul)
155 #endif
156 #else
157 #ifdef unimul
158  void sweep(typdump &dump,Base &b,int **unimul)
159 #else
160 #ifdef uninf
161  void sweep(typdump &dump,Base &b,void**nfmul)
162 #else
163 */
164  void sweep(typdump &dump,Base &b)
165 //#endif
166 //#endif
167 //#endif
168 
169 {
170  typedef typename typdump::value_type::pol_t::coeff_t coeff;
171  typedef typename Base::mon mon;
172  for(typename typdump::iterator iter=dump.begin()
173  ;iter!=dump.end();iter++)
174  {
175  for(int i=0;i<(iter->size);i++) {
176  MAC_REV_FREE<coeff>(iter->nf[i].nf,iter->nf[i].size*sizeof(coeff));
177 #ifdef sparse
178  MAC_REV_FREE<int>(iter->nf[i].nfind,iter->nf[i].size*sizeof(int));
179 #endif
180  }
181  MAC_REV_FREE<pol<mon,coeff> >(iter->nf,iter->size*sizeof(pol<mon,coeff>));
182  }
183  for(typename Base::iterator iter=b.begin()
184  ;iter!=b.end();iter++)
185  {
186  MAC_REV_FREE<mon>(iter->accept,iter->taille1*sizeof(mon));
187  MAC_REV_FREE<mon>(iter->refuse,iter->taille2*sizeof(mon));
188  }
189  //freeplacemon();
190 
191 }
192 #endif //ALREADY_memory
void * MAC_REV_REALLOC(void *ptr, int size, int newsize)
Definition: memory.hpp:49
void free(void *)
void freeplacemon()
Definition: placemon.hpp:697
Definition: pol.hpp:6
list< predicat >::iterator iterator
Definition: types.hpp:20
void CLEAR_ELEM(void *ptr, int size)
Definition: memory.hpp:26
void * malloc(YYSIZE_T)
void sweep(typdump &dump, Base &b)
Definition: memory.hpp:164
void MAC_REV_FREE(void *ptr, int size)
Definition: memory.hpp:65
void INIT_ELEM(void *ptr, int size)
Definition: memory.hpp:5
Definition: Zp.hpp:19
C coeff_t
Definition: Monom.hpp:26
void * MAC_REV_MALLOC(int size)
Definition: memory.hpp:39
iterator end()
Definition: types.hpp:30
Mon mon
Definition: solver_bb_floating.cpp:136
Definition: types.hpp:14
MSKint32t MSKint32t MSKint32t i
Definition: mosek.h:2278
Monom< COEFF, dynamicexp<'x'> > Mon
Definition: solver_bb_floating.cpp:134
iterator begin()
Definition: types.hpp:25
predicat::monom_t mon
Definition: types.hpp:19
Multivariate monomials.
Definition: Monom.hpp:21
Home  |  Download & InstallContributions