void * gim_realloc(void *ptr, size_t oldsize, size_t newsize) { void * newptr = gim_alloc(newsize); size_t copysize = oldsize<newsize?oldsize:newsize; gim_simd_memcpy(newptr,ptr,copysize); gim_free(ptr); return newptr; }
void * gim_realloc(void *ptr, size_t oldsize, size_t newsize) { /*if (g_reallocfn) return g_reallocfn(ptr,oldsize,newsize); else return realloc(ptr,newsize);*/ //return realloc(ptr,newsize); void * newptr = gim_alloc(newsize); size_t copysize = newsize> oldsize? oldsize: newsize; memcpy(newptr,ptr,copysize); gim_free(ptr,oldsize); return newptr; }
void gim_merge_contacts(GDYNAMIC_ARRAY * source_contacts, GDYNAMIC_ARRAY * dest_contacts) { dest_contacts->m_size = 0; GUINT32 source_count = source_contacts->m_size; GIM_CONTACT * psource_contacts = GIM_DYNARRAY_POINTER(GIM_CONTACT,(*source_contacts)); //create keys GIM_RSORT_TOKEN * keycontacts = (GIM_RSORT_TOKEN * )gim_alloc(sizeof(GIM_RSORT_TOKEN)*source_count); GUINT32 i; for(i=0;i<source_count;i++) { keycontacts[i].m_value = i; GIM_CALC_KEY_CONTACT(psource_contacts[i].m_point,keycontacts[i].m_key); } //sort keys GIM_QUICK_SORT_ARRAY(GIM_RSORT_TOKEN , keycontacts, source_count, RSORT_TOKEN_COMPARATOR,GIM_DEF_EXCHANGE_MACRO); // Merge contacts GIM_CONTACT * pcontact = 0; GIM_CONTACT * scontact = 0; GUINT32 key,last_key=0; for(i=0;i<source_contacts->m_size;i++) { key = keycontacts[i].m_key; scontact = &psource_contacts[keycontacts[i].m_value]; if(i>0 && last_key == key) { //merge contact if(pcontact->m_depth > scontact->m_depth + CONTACT_DIFF_EPSILON) { GIM_COPY_CONTACTS(pcontact, scontact); } } else {//add new contact GIM_DYNARRAY_PUSH_EMPTY(GIM_CONTACT,(*dest_contacts)); pcontact = GIM_DYNARRAY_POINTER_LAST(GIM_CONTACT,(*dest_contacts)); GIM_COPY_CONTACTS(pcontact, scontact); } last_key = key; } gim_free(keycontacts,0); }
static GPTR _system_buffer_alloc_data_function(const void * pdata,GUINT32 size,int /*usage*/) { void * newdata = gim_alloc(size); memcpy(newdata,pdata,size); return (GPTR)(newdata); }
static GPTR _system_buffer_alloc_function(GUINT32 size,int /*usage*/) { void * newdata = gim_alloc(size); memset(newdata,0,size); return (GPTR)newdata; }
void * gim_alloca(size_t size) { if (g_allocafn) return g_allocafn(size); else return gim_alloc(size); }
GUINT _system_buffer_alloc_data_function(const void * pdata,GUINT size,int usage) { void * newdata = gim_alloc(size); memcpy(newdata,pdata,size); return (GUINT)(newdata); }
GUINT _system_buffer_alloc_function(GUINT size,int usage) { void * newdata = gim_alloc(size); memset(newdata,0,size); return (GUINT)(newdata); }