16 #if defined(USE_VECTOR_SHAPE_POOL)
26 if (arr_link::xpool->num_allocated > 0)
32 arr_link::xpool =
nullptr;
35 if (vector_shape::xpool)
37 if (vector_shape::xpool->num_allocated > 0)
43 vector_shape::xpool =
nullptr;
46 if (vector_shapex::xpool)
48 if (vector_shapex::xpool->num_allocated > 0)
53 delete vector_shapex::xpool;
54 vector_shapex::xpool =
nullptr;
59 #if defined(THREAD_SAFE)
60 pthread_mutex_t mutex_dfpool = PTHREAD_MUTEX_INITIALIZER;
63 #if defined(THREAD_SAFE)
72 void* vector_shape::operator
new(
size_t n)
75 if (xpool && xpool->size != n)
77 cerr <<
"incorrect size requested in dfpool" <<
endl;
85 return xpool->alloc();
87 void vector_shape::operator
delete(
void* ptr, size_t)
90 if (xpool->num_allocated <= 0)
100 void* arr_link::operator
new(
size_t n)
103 if (xpool && xpool->size != n)
105 cerr <<
"incorrect size requested in dfpool" <<
endl;
113 return xpool->alloc();
115 void arr_link::operator
delete(
void* ptr, size_t)
118 if (xpool->num_allocated <= 0)
128 void* vector_shapex::operator
new(
size_t n)
131 if (xpool && xpool->size != n)
133 cerr <<
"incorrect size requested in dfpool" <<
endl;
141 return xpool->alloc();
143 void vector_shapex::operator
delete(
void* ptr, size_t)
146 if (xpool->num_allocated <= 0)
153 #if defined(__CHECK_MEMORY__)
158 void dfpool::sanity_check(
void)
166 cerr <<
"Error in dfpool structure" <<
endl;
169 cout <<
"Depth = " << depth <<
endl;
176 void dfpool::sanity_check2(
void)
184 cerr <<
"Error in dfpool adresses" <<
endl;
187 cout <<
"Depth = " << depth <<
endl;
194 void dfpool::sanity_check(
void * ptr)
203 cerr <<
"both allocated and unallocated memory at entry "
215 void dfpool::write_pointers(
int mmin,
int mmax)
222 if (index >=mmin && index <=mmax)
223 cout << index <<
" " << int(p) <<
endl;
237 #if defined(THREAD_SAFE)
238 pthread_mutex_lock(&mutex_dfpool);
243 #if defined(__CHECK_MEMORY__)
246 cerr <<
"Error in dfpool structure" <<
endl;
253 cerr <<
"Error in dfpool structure" <<
endl;
261 #if defined(__CHECK_MEMORY__)
264 cout <<
"trying to allocate already allocated object " <<
endl;
267 #if defined(THREAD_SAFE)
268 pthread_mutex_unlock(&mutex_dfpool);
272 #if defined(THREAD_SAFE)
279 #if defined(THREAD_SAFE)
285 #if defined(__CHECK_MEMORY__)
288 cerr <<
"Error in dfpool structure" <<
endl;
295 cerr <<
"Error in dfpool structure" <<
endl;
303 #if defined(__CHECK_MEMORY__)
306 cout <<
"trying to allocate already allocated object " <<
endl;
309 #if defined(THREAD_SAFE)
316 #if defined(__CHECK_MEMORY__)
322 int dfpool::bad(link * p)
328 for (
int i=1;i<=99;i++)
330 if ( p >= minaddress[i] && p <= maxaddress[i])
343 cerr <<
"bad pool object" <<
endl;
352 int dfpool::badaddress(link * p)
356 for (
int i=0;i<=nalloc;i++)
358 if ( ip == pvalues[i])
375 #if defined(THREAD_SAFE)
376 pthread_mutex_lock(&mutex_dfpool);
378 #if defined(__CHECK_MEMORY__)
383 cout <<
"trying to deallocate allocated object " <<
endl;
392 #if defined(THREAD_SAFE)
393 pthread_mutex_unlock(&mutex_dfpool);
396 #if defined(THREAD_SAFE)
404 #if defined(THREAD_SAFE)
407 #if defined(__CHECK_MEMORY__)
412 cout <<
"trying to deallocate allocated object " <<
endl;
417 link * p = (link*) b;
421 #if defined(THREAD_SAFE)
438 #if defined(__CHECK_MEMORY__)
451 size(sz < sizeof(
link *)?sizeof(
link*):sz)
459 #if defined(__CHECK_MEMORY__)
482 cerr <<
"You can not change the allocation size in mid stream" <<
endl;
493 #if defined(__CHECK_MEMORY__)
500 cerr <<
"Warning: In dfpool::deallocated, "
502 <<
") should be zero.\n";
517 #if defined(__CHECK_MEMORY__)
538 #if defined(__CHECK_MEMORY__)
539 const int pvalues_size=500000;
544 pvalues=
new int[pvalues_size];
547 const size_t overhead = 12+
sizeof(
char*);
548 const size_t chunk_size= 65000-overhead;
556 cerr <<
"error in dfpool object "
557 <<
" you must set the unit size " <<
endl;
561 char * real_start=
new char[chunk_size+6];
562 char * start=real_start+
sizeof(
char *);
565 #if defined(__CHECK_MEMORY__)
566 if (num_chunks<maxchunks)
569 maxaddress[
num_chunks]=real_start+chunk_size-1;
575 *(
char**) real_start=0;
583 #if defined(__CHECK_MEMORY__)
584 if (nalloc>pvalues_size-1)
586 cerr <<
"Error in check memory need to make pvalues bigger than "
587 << pvalues_size <<
endl;
590 pvalues[nalloc++]=int(start);
592 for (
char *p=start; p<last; p+=
size)
595 #if defined(__CHECK_MEMORY__)
596 pvalues[nalloc++]=int((
link*)(p+
size));
599 ((
link*)last)->next=0;
601 first= (
double*) start;
612 cerr <<
"error in dfpool object "
613 <<
" you must set the unit size " <<
endl;
618 for (
size_t i=1;i<=
nelem;i++)
621 for(
unsigned int j=1;j<=
size/
sizeof(double)-2;j++) *ptr++=0.0;
626 #endif // #if defined(USE_VECTOR_SHAPE_POOL)
void grow(void)
Description not yet available.
void free(void *b)
Description not yet available.
static vector_shape_pool * xpool
Description not yet available.
Description not yet available.
static vector_shape_pool * xpool
void set_size(const size_t)
Description not yet available.
void deallocate(void)
Description not yet available.
prnstream & endl(prnstream &)
virtual ~dfpool()
Destructor.
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void * alloc(void)
Description not yet available.
Description not yet available.
Holds "shape" information for vector objects.
Description not yet available.
dfpool()
Default constructor.
Description not yet available.
void clean(void)
Description not yet available.