void memory_manager::register_allocation(size_t bytes) { switch(m_enforce) { case ENFORCE_IGNORE: m_used.fetch_add(bytes); break; case ENFORCE_THROW: { size_t usage = m_used.fetch_add(bytes); if (usage > m_limit && m_limit > 0) { std::stringstream ss; tpie_print_memory_complaint(ss, bytes, usage, m_limit); throw out_of_memory_error(ss.str().c_str()); } break; } case ENFORCE_DEBUG: case ENFORCE_WARN: { size_t usage = m_used.fetch_add(bytes); if (usage > m_limit && usage - m_limit > m_maxExceeded && m_limit > 0) { m_maxExceeded = usage - m_limit; if (m_maxExceeded >= m_nextWarning) { m_nextWarning = m_maxExceeded + m_maxExceeded/8; std::ostream & os = (m_enforce == ENFORCE_DEBUG) ? log_debug() : log_warning(); tpie_print_memory_complaint(os, bytes, usage, m_limit); os << std::endl; } } break; } }; }
static void pr_append_new_chunk(pr_append_str *x, const char *s) { if (pr_append_new_chunk_external(x, s)) out_of_memory_error(); }
static void * _rb_safe_malloc(size_t x) { void *r = malloc(x); if (NULL == r) out_of_memory_error(); return r; }
void insert(int item, struct d_linked_list **list) { struct d_linked_list **head = list; struct d_linked_list *entry = malloc(sizeof(struct d_linked_list)); if (entry == NULL) { out_of_memory_error(); } entry->item = item; entry->prev = NULL; entry->next = *head; if(*head != NULL) { (*head)->prev = entry; } *head = entry; }
void image_dct(INT32 args) { rgbd_group *area,*val; struct object *o; struct image *img; INT32 x,y,u,v; double xsz2,ysz2,enh,xp,yp,dx,dy; double *costbl; rgb_group *pix; CHECK_INIT(); get_all_args(NULL, args, "%d%d", &x, &y); x = MAXIMUM(1, x); y = MAXIMUM(1, y); #ifdef DCT_DEBUG fprintf(stderr,"%lu bytes, %lu bytes\n", (unsigned long)(sizeof(rgbd_group)*THIS->xsize*THIS->ysize), (unsigned long)(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)); #endif area=xalloc(sizeof(rgbd_group)*THIS->xsize*THIS->ysize+1); if (!(costbl=malloc(sizeof(double)*THIS->xsize+1))) { free(area); out_of_memory_error(NULL, -1, 0); } o=clone_object(image_program,0); img=(struct image*)(o->storage); *img=*THIS; img->xsize = x; img->ysize = y; if (!(img->img=malloc(sizeof(rgb_group)* img->xsize*img->ysize+RGB_VEC_PAD))) { free(area); free(costbl); free_object(o); out_of_memory_error(NULL, -1, 0); } xsz2=THIS->xsize*2.0; ysz2=THIS->ysize*2.0; enh=(8.0/THIS->xsize)*(8.0/THIS->ysize); for (u=0; u<THIS->xsize; u++) { double d,z0; rgbd_group sum; for (v=0; v<THIS->ysize; v++) { d=(u?1:c0)*(v?1:c0)/4.0; sum.r=sum.g=sum.b=0; pix=THIS->img; for (x=0; x<THIS->xsize; x++) costbl[x]=cos( (2*x+1)*u*pi/xsz2 ); for (y=0; y<THIS->ysize; y++) { z0=cos( (2*y+1)*v*pi/ysz2 ); for (x=0; x<THIS->xsize; x++) { double z; z = costbl[x] * z0; sum.r += (float)(pix->r*z); sum.g += (float)(pix->g*z); sum.b += (float)(pix->b*z); pix++; } } sum.r *= (float)d; sum.g *= (float)d; sum.b *= (float)d; area[u+v*THIS->xsize]=sum; } #ifdef DCT_DEBUG fprintf(stderr,"."); fflush(stderr); #endif } #ifdef DCT_DEBUG fprintf(stderr,"\n"); #endif dx=((double)(THIS->xsize-1))/(img->xsize); dy=((double)(THIS->ysize-1))/(img->ysize); pix=img->img; for (y=0,yp=0; y<img->ysize; y++,yp+=dy) { double z0; rgbd_group sum; for (x=0,xp=0; x<img->xsize; x++,xp+=dx) { sum.r=sum.g=sum.b=0; val=area; for (u=0; u<THIS->xsize; u++) costbl[u]=cos( (2*xp+1)*u*pi/xsz2 ); for (v=0; v<THIS->ysize; v++) { z0=cos( (2*yp+1)*v*pi/ysz2 )*(v?1:c0)/4.0; for (u=0; u<THIS->xsize; u++) { double z; z = (u?1:c0) * costbl[u] * z0; sum.r += (float)(val->r*z); sum.g += (float)(val->g*z); sum.b += (float)(val->b*z); val++; } } sum.r *= (float)enh; sum.g *= (float)enh; sum.b *= (float)enh; pix->r=testrange((int)(sum.r+0.5)); pix->g=testrange((int)(sum.g+0.5)); pix->b=testrange((int)(sum.b+0.5)); pix++; } #ifdef DCT_DEBUG fprintf(stderr,"."); fflush(stderr); #endif } free(area); free(costbl); pop_n_elems(args); push_object(o); }