////////////// // Mutators // ////////////// void image::resize(image::size_type newWidth, image::size_type newHeight) { // check if new size == old size if(width() == newWidth && height() == newHeight) return; // dealloc and re-alloc _dealloc(); _alloc(newWidth, newHeight); // Done. }
/** * vsg_matrix3@t@_identity_new: * * Allocates a new #VsgMatrix3@t@ with Identity component (%1 on the diagonal, * %0 elsewhere). * * Returns: new #VsgMatrix3@t@ instance */ VsgMatrix3@t@ *vsg_matrix3@t@_identity_new () { #if _USE_G_SLICES VsgMatrix3@t@ *result = g_slice_new (VsgMatrix3@t@); #else VsgMatrix3@t@ *result = _matrix3@t@_alloc (); #endif vsg_matrix3@t@_identity_inline (result); return result; }
// support for C++ new and delete void * MemMgrItf :: _new ( size_t bytes ) { FUNC_ENTRY (); // allocate new object plus header size Refcount * obj = ( Refcount * ) _alloc ( bytes, true ); obj -> mmgr = ( MemMgrItf * ) duplicate (); obj -> obj_size = bytes; // return allocation return ( void * ) obj; }
string16 *s16_stacksize_new(size_t stacksize, size_t bufsize) { string16 *s16; size_t size = sizeof(string16) - sizeof(_16b) * S16_STACKBUF_MAX + sizeof(_16b) * stacksize; s16 = (string16*)malloc(size); if (s16 == NULL) return NULL; s16->stacksize = stacksize; _alloc(s16, bufsize); _set_define_encode(s16); return s16; }
/** * vsg_vector2@t@_new: * @x: abscissa * @y: ordinate * * Allocates a new instance of #VsgVector2@t@. This instance MUST be freed only * with vsg_vector2@t@_free(). * * Returns: new #VsgVector2@t@ instance. */ VsgVector2@t@ *vsg_vector2@t@_new(@type@ x, @type@ y) { #if _USE_G_SLICES VsgVector2@t@ *result = g_slice_new (VsgVector2@t@); #else VsgVector2@t@ *result = _vector2@t@_alloc (); #endif vsg_vector2@t@_set(result, x, y); return result; }
void* MemoryPoolStaticMalloc::alloc(size_t p_bytes,const char *p_description) { #if DEFAULT_ALIGNMENT == 1 return _alloc(p_bytes, p_description); #else size_t total; #if defined(_add_overflow) if (_add_overflow(p_bytes, DEFAULT_ALIGNMENT, &total)) return NULL; #else total = p_bytes + DEFAULT_ALIGNMENT; #endif uint8_t* ptr = (uint8_t*)_alloc(total, p_description); ERR_FAIL_COND_V( !ptr, ptr ); int ofs = (DEFAULT_ALIGNMENT - ((uintptr_t)ptr & (DEFAULT_ALIGNMENT - 1))); ptr[ofs-1] = ofs; return (void*)(ptr + ofs); #endif };
/* global functions */ int vector_init(vector_t *v, size_t dt_size, size_t capa){ v->data = _alloc(dt_size * capa); if(v->data == 0x0) return -1; v->capacity = capa; v->size = 0; v->dt_size = dt_size; return 0; }
/** * vsg_quaternion@t@_identity_new: * * Allocates a new #VsgQuaternion@t@ with Identity component. * * Returns: new #VsgQuaternion@t@ instance */ VsgQuaternion@t@ *vsg_quaternion@t@_identity_new () { #if _USE_G_SLICES VsgQuaternion@t@ *result = g_slice_new (VsgQuaternion@t@); #else VsgQuaternion@t@ *result = _quaternion@t@_alloc (); #endif vsg_quaternion@t@_identity_inline (result); return result; }
/** * vsg_matrix3@t@_new: * @a00: a #@type@ * @a01: a #@type@ * @a02: a #@type@ * @a10: a #@type@ * @a11: a #@type@ * @a12: a #@type@ * @a20: a #@type@ * @a21: a #@type@ * @a22: a #@type@ * * Allocates a new #VsgMatrix3@t@. Arguments specify new matrix components. * * Returns: new #VsgMatrix3@t@ instance */ VsgMatrix3@t@ *vsg_matrix3@t@_new (@type@ a00, @type@ a01, @type@ a02, @type@ a10, @type@ a11, @type@ a12, @type@ a20, @type@ a21, @type@ a22) { VsgMatrix3@t@ *result = _matrix3@t@_alloc (); vsg_matrix3@t@_set_inline (result, a00, a01, a02, a10, a11, a12, a20, a21, a22); return result; }
/** * vsg_vector3@t@_new: * @x: abscissa * @y: ordinate * @z: Z coordinate * * Allocates a new instance of #VsgVector3@t@. This instance MUST be freed only * with vsg_vector3@t@_free(). * * Returns: new #VsgVector3@t@ instance. */ VsgVector3@t@ *vsg_vector3@t@_new (@type@ x, @type@ y, @type@ z) { #if _USE_G_SLICES VsgVector3@t@ *result = g_slice_new (VsgVector3@t@); #else VsgVector3@t@ *result = _vector3@t@_alloc (); #endif vsg_vector3@t@_set_inline (result, x, y, z); return result; }
void read_btc(char* path, struct c_img* out_img){ int fd, nr_blocks, i, j = 0, k, ii; char *big_buf; struct bits tmp; fd = _open_for_read(path); read(fd, &out_img->width, sizeof(int)); read(fd, &out_img->height, sizeof(int)); nr_blocks = out_img->width * out_img->height / (BLOCK_SIZE * BLOCK_SIZE); out_img->blocks = (struct block*) _alloc(nr_blocks * sizeof(struct block)); big_buf = (char*) _alloc(nr_blocks * (2 + BLOCK_SIZE * BLOCK_SIZE / BITS_IN_BYTE)); _read_buffer(fd, big_buf, nr_blocks * (2 + BLOCK_SIZE * BLOCK_SIZE / BITS_IN_BYTE)); for (i=0; i<nr_blocks; i++){ //read a and b out_img->blocks[i].a = big_buf[j++]; out_img->blocks[i].b = big_buf[j++]; //read bitplane k = 0; for (ii=0; ii<BLOCK_SIZE * BLOCK_SIZE / BITS_IN_BYTE; ii++){ tmp = *((struct bits*)&big_buf[j++]); out_img->blocks[i].bitplane[k++] = tmp.bit0; out_img->blocks[i].bitplane[k++] = tmp.bit1; out_img->blocks[i].bitplane[k++] = tmp.bit2; out_img->blocks[i].bitplane[k++] = tmp.bit3; out_img->blocks[i].bitplane[k++] = tmp.bit4; out_img->blocks[i].bitplane[k++] = tmp.bit5; out_img->blocks[i].bitplane[k++] = tmp.bit6; out_img->blocks[i].bitplane[k++] = tmp.bit7; } } free_align(big_buf); close(fd); }
/** * vsg_matrix3@t@_clone: * @src: a #VsgMatrix3@t@. * * Duplicates @src. * * Returns: a copy of @src. */ VsgMatrix3@t@ *vsg_matrix3@t@_clone (const VsgMatrix3@t@ *src) { VsgMatrix3@t@ *dst; #ifdef VSG_CHECK_PARAMS g_return_val_if_fail (src != NULL, NULL); #endif dst = _matrix3@t@_alloc (); vsg_matrix3@t@_copy_inline (src, dst); return dst; }
void CMyProblem::GenerateRandomProblemWNC(int _n, int _p, string _name, int max_w) { _alloc(_n); Set_p(_p); Set_name(_name.c_str()); for (int i=0; i<n; i++) { r[i]=myRandom(0, p*i); w[i]=myRandom(1,(max_w!=0)?max_w:100); //cout << r[i] << ' ' << w[i]<< endl; } //cout << endl; }
int secprintf(const char * secret, const char * msg, const char * name) { char *hash, *salt, *fullmsg; int res; size_t len; #ifdef _KERNEL if (test161_sem == NULL) { panic("test161_sem is NULL. Your kernel is missing test161_bootstrap."); } P(test161_sem); #endif hash = salt = fullmsg = NULL; // test161 expects "name: msg" len = strlen(name) + strlen(msg) + 3; // +3 for " :" and null terminator fullmsg = (char *)_alloc(len); if (fullmsg == NULL) { res = -ENOMEM; goto out; } snprintf(fullmsg, len, "%s: %s", name, msg); res = hmac_salted(fullmsg, len-1, secret, strlen(secret), &hash, &salt); if (res) { res = -res; goto out; } #ifdef _KERNEL res = kprintf("\n(%s, %s, %s, %s: %s)\n", name, hash, salt, name, msg); #else res = say("\n(%s, %s, %s, %s: %s)\n", name, hash, salt, name, msg); #endif out: // These may be NULL, but that's OK _free(hash); _free(salt); _free(fullmsg); #ifdef _KERNEL V(test161_sem); #endif return res; }
/** * vsg_quaternion@t@_new: * @x: abscissa * @y: ordinate * @z: Z coordinate * @w: W coordinate * * Allocates a new instance of #VsgQuaternion@t@. This instance MUST * be freed only with vsg_quaternion@t@_free(). * * Returns: new #VsgQuaternion@t@ instance. */ VsgQuaternion@t@ *vsg_quaternion@t@_new (@type@ x, @type@ y, @type@ z, @type@ w) { #if _USE_G_SLICES VsgQuaternion@t@ *result = g_slice_new (VsgQuaternion@t@); #else VsgQuaternion@t@ *result = _quaternion@t@_alloc (); #endif vsg_quaternion@t@_set_inline (result, x, y, z, w); return result; }
GCAllocation* LargeArena::alloc(size_t size) { registerGCManagedBytes(size); LOCK_REGION(heap->lock); // printf ("allocLarge %zu\n", size); LargeObj* obj = _alloc(size + sizeof(GCAllocation) + sizeof(LargeObj)); obj->size = size; nullNextPrev(obj); insertIntoLL(&head, obj); return obj->data; }
e_node* stmt(void) { e_node* top; if(curToken==LPAREN) { level++; match(LPAREN,TRUE); top=(e_node*)_alloc(sizeof(e_node)); e_node* child_n=application(); top->next=child_n; e_node* para_list=child_n; while(curToken!=RPAREN) { //fprintf(stderr,"curToken: %d\n",curToken); para_list->child_n=stmt(); para_list=para_list->child_n; } level--; if(level) match(RPAREN,TRUE); else match(RPAREN,FALSE); if (para_list) { para_list->child_n=NULL; } } else if(curToken==NUM) { //fprintf(stderr,"Num\n"); top=num(); } else if(curToken==ID) { //fprintf(stderr,"Id\n"); top=id(); } else if(curToken==STRING) { top=init_node(); top->child_e = strdup(TokenString); if (level) match(STRING,TRUE ); else match(STRING,FALSE); } else if(curToken==EndOfFile) { top=NULL; } else { //fprintf(stderr,"Error\n"); fprintf(stderr,"stmt unmatch\n"); return NULL; } return top; }
LPWSTR xToUnicodeEx(DWORD codePage,LPSTR source,int size) { if (size == -1) size=lstrlenA(source); int destSize=xToUnicode(codePage,source,size,NULL,0); if (destSize > 0) { destSize+=sizeof(BYTE); LPWSTR dest=(LPWSTR)_alloc(destSize*sizeof(WCHAR)); if (dest) { xToUnicode(codePage,source,size,dest,destSize); return dest; } } return NULL; }
LPSTR UnicodeToXEx(DWORD codePage,const LPWSTR source,int size) { if (size == -1) size=lstrlenW(source); int destSize=UnicodeToX(codePage,source,size,NULL,0); if (destSize > 0) { destSize+=sizeof(BYTE); LPSTR dest=(LPSTR)_alloc(destSize*sizeof(BYTE)); if (dest) { UnicodeToX(codePage,source,size,dest,destSize); return dest; } } return NULL; }
/** * vsg_matrix3@t@_new: * @a00: a #@type@ * @a01: a #@type@ * @a02: a #@type@ * @a10: a #@type@ * @a11: a #@type@ * @a12: a #@type@ * @a20: a #@type@ * @a21: a #@type@ * @a22: a #@type@ * * Allocates a new #VsgMatrix3@t@. Arguments specify new matrix components. * * Returns: new #VsgMatrix3@t@ instance */ VsgMatrix3@t@ *vsg_matrix3@t@_new (@type@ a00, @type@ a01, @type@ a02, @type@ a10, @type@ a11, @type@ a12, @type@ a20, @type@ a21, @type@ a22) { #if _USE_G_SLICES VsgMatrix3@t@ *result = g_slice_new (VsgMatrix3@t@); #else VsgMatrix3@t@ *result = _matrix3@t@_alloc (); #endif vsg_matrix3@t@_set_inline (result, a00, a01, a02, a10, a11, a12, a20, a21, a22); return result; }
void texture::create(const vec2u &size, bool smooth) { _alloc(); bind(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); if(smooth) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } _size = size; }
bool texture::load(const std::string &path, bool smooth, bool mipmap) { _name = path; for(auto &i: render::_internal::objectList) if(texture *tex = dynamic_cast<texture*>(i)) if(tex->_name == _name) { _log::out("Found texture: %s [ OK ]\n", path.c_str()); _obj = tex->_obj; _size = tex->_size; return 1; } FREE_IMAGE_FORMAT format = FreeImage_GetFileType(path.c_str(), 0); FIBITMAP* image = FreeImage_Load(format, path.c_str()); _log::out("Loading texture: %s ", path.c_str()); if(!image) { _log::out("[FAIL]\n"); return 0; } image = FreeImage_ConvertTo32Bits(image); _size.x = FreeImage_GetWidth(image); _size.y = FreeImage_GetHeight(image); uchar* pixeles = FreeImage_GetBits(image); _alloc(); bind(); if(mipmap) gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, _size.x, _size.y, GL_BGRA, GL_UNSIGNED_BYTE, pixeles); else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _size.x, _size.y, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixeles); if(smooth) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } FreeImage_Unload(image); _log::out("[ OK ] (%dx%d)\n", _size.x, _size.y); return 1; }
char *rev_simple(char *pstr) { unsigned int len = strlen(pstr); char *rstr = _alloc(len); if (len == 0) return rstr; char *pend = pstr + len - 1; char *p = rstr; unsigned int l = len; do { *p++ = *pend--; } while (--l > 0); *p = '\0'; return rstr; }
/** * vsg_quaternion@t@_clone: * @src: a #VsgQuaternion@t@ * * Duplicates @src. * * Returns: a newly allocated copy of @src. */ VsgQuaternion@t@ *vsg_quaternion@t@_clone (const VsgQuaternion@t@ *src) { VsgQuaternion@t@ *dst; #ifdef VSG_CHECK_PARAMS g_return_val_if_fail (src != NULL, NULL); #endif #if _USE_G_SLICES dst = g_slice_new (VsgQuaternion@t@); #else dst = _quaternion@t@_alloc (); #endif vsg_quaternion@t@_copy_inline (src, dst); return dst; }
CMyProblem& CMyProblem::operator= (const CMyProblem &src) { if (this == &src) return *this; if (src.n!=n) _destroy(); if (src.IsInvalid()) { n=0; return *this; } _alloc(src.n); _copy(src); return *this; }
ReusableObject *PagerReuse::request(void) { ReusableObject *obj = NULL; __AUTOLOCK(this); if(!limit || count < limit) { if(freelist) { ++count; obj = freelist; freelist = next(obj); } else { ++count; return (ReusableObject *)_alloc(osize); } } return obj; }
// insert to the position in front of p. bool insert(pointer ptr, element val) { if( ifree == NPTR ) return false; // 没有结点,直接返回 if( ptr == idata ) { // 有一个节点 pointer np = _alloc(val); nextof(np) = idata; idata = np; return true; } else { // 其他情况,先找 ptr 的前驱,再插入 pointer p = idata; while( p != NPTR ) { if( nextof(p) == ptr ) { // find p -- the prev node of ptr. return insert_after(p, val); // insert val after p. } p = nextof(p); } } return false; }
struct ringbuffer_block * ringbuffer_alloc(struct ringbuffer * rb, int size) { int align_length = ALIGN(sizeof(struct ringbuffer_block) + size); int i; for (i=0;i<2;i++) { int free_size = 0; struct ringbuffer_block * blk = block_ptr(rb, rb->head); do { if (blk->length >= sizeof(struct ringbuffer_block) && blk->id >= 0) return NULL; free_size += ALIGN(blk->length); if (free_size >= align_length) { return _alloc(rb, free_size , size); } blk = block_next(rb, blk); } while(blk); rb->head = 0; } return NULL; }
bool ArchInternalEnumFiles(HZIP hZip,ARCHENUMNAMESCALLBACKW *lpCallback,bool bAnsi) { bool r=false; ZIPDECOMPRESSION *p=(ZIPDECOMPRESSION *)hZip; if ((hZip) && (((ZIPDECOMPRESSION *)hZip)->bHandleType == HT_DECOMPRESSOR) && (lpCallback)) { ZIPDECOMPRESSION *p=(ZIPDECOMPRESSION*)_alloc(sizeof(ZIPDECOMPRESSION)); if (p) { memcpy(p,hZip,sizeof(ZIPDECOMPRESSION)); p->bOnlyEnum=true; p->bEnumAnsi=bAnsi; p->lpEnumProc=lpCallback; r=ArchExtractFilesW(p,L"0"); MemFree(p); } } else ArchSetLastError(ARCH_INVALID_PARAMETER); return r; }
int vector_add(vector_t *v, void *data){ void *t; if(v->size >= v->capacity){ v->capacity *= 2; t = _alloc(v->capacity * v->dt_size); if(t == 0x0) return -1; memcpy(t, v->data, v->size * v->dt_size); _free(v->data); v->data = t; } memcpy(v->data + v->size * v->dt_size, data, v->dt_size); v->size++; return 0; }