// add the given Displayable as a child (assuming it is one) void Displayable::add_child(Displayable *d) { // append child to list of children children[num_children++] = d; if (num_children == max_children) { void *tmp = vmd_alloc(max_children*2*sizeof(Displayable*)); memcpy(tmp,children,max_children*sizeof(Displayable*)); vmd_dealloc(children); children = (Displayable **)tmp; max_children *= 2; } }
// function to resize allocations depending on whether or not the allocator // provides a realloc() function or not. void * vmd_resize_alloc(void *ptr, size_t oldsize, size_t newsize) { void *newptr=NULL; if (ptr == NULL) { newptr = vmd_alloc(newsize); return newptr; } if (vmd_realloc != NULL) { newptr = vmd_realloc(ptr, newsize); } if (newptr == NULL) { newptr = vmd_alloc(newsize); if (newptr != NULL) { memcpy(newptr, ptr, oldsize); vmd_dealloc(ptr); } } return newptr; }
int VolumeTexture::allocateTextureMap(int npixels) { texid = 0; if (texmap) { vmd_dealloc(texmap); texmap = NULL; } texmap = (unsigned char *) vmd_alloc(npixels*3*sizeof(unsigned char)); if (texmap == NULL) { msgErr << "Texture map allocation failed, out of memory?" << sendmsg; return FALSE; } memset(texmap, 0, npixels*3*sizeof(unsigned char)); texid = VMDApp::get_texserialnum(); return TRUE; }
// does all the creation work after variables have been initialized void Displayable::do_create() { children = (Displayable **)vmd_alloc(16*sizeof(Displayable*)); num_children = 0; max_children = 16; // initialize the display command list cmdList = new VMDDisplayList; // initialize flags and scalar settings needMatrixRecalc = TRUE; isFixed = FALSE; // initialize display list cmdList->mat = tm; }
void *Displayable::operator new(size_t n) { return vmd_alloc(n); }