void ofPixels_<PixelType>::setFromPixels(const PixelType * newPixels, size_t w, size_t h, ofImageType type){ allocate(w,h,type); setFromPixels(newPixels,w,h,ofPixelFormatFromImageType(type)); }
// ignores allocationtype and protection EXPORT LPVOID VirtualAllocEx(HANDLE hProcess, LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect){ unsigned int addy = (unsigned int) allocate(hProcess, (int) lpAddress, dwSize); return (LPVOID) addy; }
Py_Exit(sts); /* Calls PyThread_exit_prog(sts) or _PyThread_exit_prog(sts) */ for (;;) { } /* Should not be reached */ } #endif static PyObject * thread_PyThread_allocate_lock(PyObject *self, PyObject *args) { if (!PyArg_NoArgs(args)) return NULL; return (PyObject *) newlockobject(); } static char allocate_doc[] = "allocate_lock() -> lock object\n\ (allocate() is an obsolete synonym)\n\ \n\ Create a new lock object. See LockType.__doc__ for information about locks."; static PyObject * thread_get_ident(PyObject *self, PyObject *args) { long ident; if (!PyArg_NoArgs(args)) return NULL; ident = PyThread_get_thread_ident(); if (ident == -1) { PyErr_SetString(ThreadError, "no current thread ident"); return NULL; } return PyInt_FromLong(ident);
void get_rld_state_symbols( void) { unsigned long i, j, save_nname; NXStream *stream; struct mach_header **headers; char *object_addr; struct load_command *lc; struct symtab_command *st; if(grld_nloaded_states == 0) return; headers = allocate(grld_nloaded_states * sizeof(struct mach_header *)); /* * Load the a_outname file as the base file. */ stream = NXOpenFile(fileno(stdout), NX_WRITEONLY); if(rld_load_basefile(stream, a_outname) == 0){ NXFlush(stream); fflush(stdout); fatal("can't load: %s as base file", a_outname); } /* * Preform an rld_load() for each state at the state's address. */ for(i = 0; i < grld_nloaded_states; i++){ link_edit_address = (unsigned long)grld_loaded_state[i].header_addr; rld_address_func(address_func); if(rld_load(stream, &(headers[i]), grld_loaded_state[i].object_filenames, RLD_DEBUG_OUTPUT_FILENAME) == 0){ NXFlush(stream); fflush(stdout); fatal("rld_load() failed"); } } /* * Pass 1 count symbols */ save_nname = nname; for(i = 0; i < grld_nloaded_states; i++){ st = NULL; object_addr = (char *)headers[i]; lc = (struct load_command *) (object_addr + sizeof(struct mach_header)); for(j = 0; j < headers[i]->ncmds; j++){ if(st == NULL && lc->cmd == LC_SYMTAB){ st = (struct symtab_command *)lc; count_func_symbols((struct nlist *) (object_addr + st->symoff), st->nsyms, object_addr + st->stroff, st->strsize); } lc = (struct load_command *)((char *)lc + lc->cmdsize); } } /* * Reallocate the data structures for the symbols. */ nl = (nltype *)realloc(nl, (nname + 1) * sizeof(nltype)); if(nl == NULL) fatal("No room for %lu bytes of symbol table\n", (nname + 1) * sizeof(nltype)); npe = nl + (save_nname + 1); memset(npe, '\0', (nname - save_nname) * sizeof(nltype)); /* * Pass 2 load symbols. */ for(i = 0; i < grld_nloaded_states; i++){ st = NULL; object_addr = (char *)headers[i]; lc = (struct load_command *) (object_addr + sizeof(struct mach_header)); for(j = 0; j < headers[i]->ncmds; j++){ if(st == NULL && lc->cmd == LC_SYMTAB){ st = (struct symtab_command *)lc; load_func_symbols((struct nlist *) (object_addr + st->symoff), st->nsyms, object_addr + st->stroff, st->strsize, 0); } lc = (struct load_command *)((char *)lc + lc->cmdsize); } } #ifdef DEBUG if(debug & RLDDEBUG){ for(i = save_nname + 1; i < nname + 1; i++){ printf("[get_rld_state_symbols] 0x%08x\t%s\n", (unsigned int)nl[i].value, nl[i].name); } } #endif /* DEBUG */ /* * Resort the symbol table. */ qsort(nl, nname + 1, sizeof(nltype), (int (*)(const void *, const void *))valcmp); free(headers); }
static void ___kmp_env_blk_parse_windows( kmp_env_blk_t * block, // M: Env block to fill. char const * env // I: Pointer to Windows* OS (DOS) environment block. ) { char * bulk = NULL; kmp_env_var_t * vars = NULL; int count = 0; // Number of used elements in vars array. int size = 0; // Size of bulk. char * name; // Pointer to name of variable. char * value; // Pointer to value. if ( env != NULL ) { // Loop thru all the vars in environment block. Count variables, find size of block. { char const * var; // Pointer to beginning of var. int len; // Length of variable. count = 0; var = env; // The first variable starts and beginning of environment block. len = strlen( var ); while ( len != 0 ) { ++ count; size = size + len + 1; var = var + len + 1; // Move pointer to the beginning of the next variable. len = strlen( var ); }; // while size = size + 1; // Total size of env block, including terminating zero byte. } // Copy original block to bulk, we will modify bulk, not original block. bulk = (char *) allocate( size ); memcpy( bulk, env, size ); // Allocate vars array. vars = (kmp_env_var_t *) allocate( count * sizeof( kmp_env_var_t ) ); // Loop thru all the vars, now in bulk. { char * var; // Pointer to beginning of var. int len; // Length of variable. count = 0; var = bulk; len = strlen( var ); while ( len != 0 ) { // Save variable in vars array. __kmp_str_split( var, '=', & name, & value ); vars[ count ].name = name; vars[ count ].value = value; ++ count; // Get the next var. var = var + len + 1; len = strlen( var ); }; // while } }; // if // Fill out result. block->bulk = bulk; block->vars = vars; block->count = count; }; // ___kmp_env_blk_parse_windows
void* FixedAllocator::allocate(size_t size) { return allocate(size, vm::BytesPerWord); }
bool ofGstVideoPlayer::loadMovie(string name){ close(); if( name.find( "file://",0 ) != string::npos){ bIsStream = false; }else if( name.find( "://",0 ) == string::npos){ name = "file:///"+ofToDataPath(name,true); bIsStream = false; }else{ bIsStream = true; } ofLog(OF_LOG_VERBOSE,"loading "+name); ofGstUtils::startGstMainLoop(); #if GST_VERSION_MAJOR==0 GstElement * gstPipeline = gst_element_factory_make("playbin2","player"); #else GstElement * gstPipeline = gst_element_factory_make("playbin","player"); #endif g_object_set(G_OBJECT(gstPipeline), "uri", name.c_str(), (void*)NULL); // create the oF appsink for video rgb without sync to clock GstElement * gstSink = gst_element_factory_make("appsink", "app_sink"); gst_base_sink_set_sync(GST_BASE_SINK(gstSink), true); gst_app_sink_set_max_buffers(GST_APP_SINK(gstSink), 8); gst_app_sink_set_drop (GST_APP_SINK(gstSink),true); gst_base_sink_set_max_lateness (GST_BASE_SINK(gstSink), -1); #if GST_VERSION_MAJOR==0 int bpp; string mime; switch(internalPixelFormat){ case OF_PIXELS_MONO: mime = "video/x-raw-gray"; bpp = 8; break; case OF_PIXELS_RGB: mime = "video/x-raw-rgb"; bpp = 24; break; case OF_PIXELS_RGBA: case OF_PIXELS_BGRA: mime = "video/x-raw-rgb"; bpp = 32; break; default: mime = "video/x-raw-rgb"; bpp=24; break; } GstCaps *caps = gst_caps_new_simple(mime.c_str(), "bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, 24, "endianness",G_TYPE_INT,4321, "red_mask",G_TYPE_INT,0xff0000, "green_mask",G_TYPE_INT,0x00ff00, "blue_mask",G_TYPE_INT,0x0000ff, "alpha_mask",G_TYPE_INT,0x000000ff, NULL); #else int bpp; string mime="video/x-raw"; string format; switch(internalPixelFormat){ case OF_PIXELS_MONO: format = "GRAY8"; bpp = 8; break; case OF_PIXELS_RGB: format = "RGB"; bpp = 24; break; case OF_PIXELS_RGBA: format = "RGBA"; bpp = 32; break; case OF_PIXELS_BGRA: format = "BGRA"; bpp = 32; break; default: format = "RGB"; bpp=24; break; } GstCaps *caps = gst_caps_new_simple(mime.c_str(), "format", G_TYPE_STRING, format.c_str(), /*"bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, 24, "endianness",G_TYPE_INT,4321, "red_mask",G_TYPE_INT,0xff0000, "green_mask",G_TYPE_INT,0x00ff00, "blue_mask",G_TYPE_INT,0x0000ff, "alpha_mask",G_TYPE_INT,0x000000ff,*/ NULL); #endif gst_app_sink_set_caps(GST_APP_SINK(gstSink), caps); gst_caps_unref(caps); if(threadAppSink){ GstElement * appQueue = gst_element_factory_make("queue","appsink_queue"); g_object_set(G_OBJECT(appQueue), "leaky", 0, "silent", 1, (void*)NULL); GstElement* appBin = gst_bin_new("app_bin"); gst_bin_add(GST_BIN(appBin), appQueue); GstPad* appQueuePad = gst_element_get_static_pad(appQueue, "sink"); GstPad* ghostPad = gst_ghost_pad_new("app_bin_sink", appQueuePad); gst_object_unref(appQueuePad); gst_element_add_pad(appBin, ghostPad); gst_bin_add_many(GST_BIN(appBin), gstSink, NULL); gst_element_link_many(appQueue, gstSink, NULL); g_object_set (G_OBJECT(gstPipeline),"video-sink",appBin,(void*)NULL); }else{ g_object_set (G_OBJECT(gstPipeline),"video-sink",gstSink,(void*)NULL); } #ifdef TARGET_WIN32 GstElement *audioSink = gst_element_factory_make("directsoundsink", NULL); g_object_set (G_OBJECT(gstPipeline),"audio-sink",audioSink,(void*)NULL); #endif videoUtils.setPipelineWithSink(gstPipeline,gstSink,bIsStream); if(!bIsStream) return allocate(bpp); else return true; }
void AudioInputAnalogStereo::update(void) { audio_block_t *new_left=NULL, *out_left=NULL; audio_block_t *new_right=NULL, *out_right=NULL; int32_t tmp; int16_t s, *p, *end; //Serial.println("update"); // allocate new block (ok if both NULL) new_left = allocate(); if (new_left == NULL) { new_right = NULL; } else { new_right = allocate(); if (new_right == NULL) { release(new_left); new_left = NULL; } } __disable_irq(); if (offset_left < AUDIO_BLOCK_SAMPLES || offset_right < AUDIO_BLOCK_SAMPLES) { // the DMA hasn't filled up both blocks if (block_left == NULL) { block_left = new_left; offset_left = 0; new_left = NULL; } if (block_right == NULL) { block_right = new_right; offset_right = 0; new_right = NULL; } __enable_irq(); if (new_left) release(new_left); if (new_right) release(new_right); return; } // the DMA filled blocks, so grab them and get the // new blocks to the DMA, as quickly as possible out_left = block_left; out_right = block_right; block_left = new_left; block_right = new_right; offset_left = 0; offset_right = 0; __enable_irq(); // // DC Offset Removal Filter // 1-pole digital high-pass filter implementation // y = a*(x[n] - x[n-1] + y[n-1]) // The coefficient "a" is as follows: // a = UNITY*e^(-2*pi*fc/fs) // fc = 2 @ fs = 44100 // // DC removal, LEFT p = out_left->data; end = p + AUDIO_BLOCK_SAMPLES; do { tmp = (uint16_t)(*p); tmp = ( ((int32_t) tmp) << 14); int32_t acc = hpf_y1[0] - hpf_x1[0]; acc += tmp; hpf_y1[0] = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 1); hpf_x1[0] = tmp; s = signed_saturate_rshift(hpf_y1[0], 16, 14); *p++ = s; } while (p < end); // DC removal, RIGHT p = out_right->data; end = p + AUDIO_BLOCK_SAMPLES; do { tmp = (uint16_t)(*p); tmp = ( ((int32_t) tmp) << 14); int32_t acc = hpf_y1[1] - hpf_x1[1]; acc += tmp; hpf_y1[1]= FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 1); hpf_x1[1] = tmp; s = signed_saturate_rshift(hpf_y1[1], 16, 14); *p++ = s; } while (p < end); // then transmit the AC data transmit(out_left, 0); release(out_left); transmit(out_right, 1); release(out_right); }
void gen_asm_addr(IR *ir) { int x = allocate(ir->rd); set_dirty(x); emit_asm(addiu, "%s, $sp, %d # get %s's address", reg_to_s(x), sp_offset - ir->rs->address, print_operand(ir->rs)); }
/* Callback for JVMTI_EVENT_CLASS_FILE_LOAD_HOOK */ static void JNICALL cbClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv* env, jclass class_being_redefined, jobject loader, const char* name, jobject protection_domain, jint class_data_len, const unsigned char* class_data, jint* new_class_data_len, unsigned char** new_class_data) { enterCriticalSection(jvmti); { /* It's possible we get here right after VmDeath event, be careful */ if ( !gdata->vmDead ) { const char * classname; /* Name can be NULL, make sure we avoid SEGV's */ if ( name == NULL ) { classname = java_crw_demo_classname(class_data, class_data_len, NULL); if ( classname == NULL ) { fatal_error("ERROR: No classname in classfile\n"); } } else { classname = strdup(name); if ( classname == NULL ) { fatal_error("ERROR: Ran out of malloc() space\n"); } } *new_class_data_len = 0; *new_class_data = NULL; /* The tracker class itself? */ if ( strcmp(classname, STRING(HEAP_TRACKER_class)) != 0 ) { jint cnum; int systemClass; unsigned char *newImage; long newLength; /* Get number for every class file image loaded */ cnum = gdata->ccount++; /* Is it a system class? If the class load is before VmStart * then we will consider it a system class that should * be treated carefully. (See java_crw_demo) */ systemClass = 0; if ( !gdata->vmStarted ) { systemClass = 1; } newImage = NULL; newLength = 0; /* Call the class file reader/write demo code */ java_crw_demo(cnum, classname, class_data, class_data_len, systemClass, STRING(HEAP_TRACKER_class), "L" STRING(HEAP_TRACKER_class) ";", NULL, NULL, NULL, NULL, STRING(HEAP_TRACKER_newobj), "(Ljava/lang/Object;)V", STRING(HEAP_TRACKER_newarr), "(Ljava/lang/Object;)V", &newImage, &newLength, NULL, NULL); /* If we got back a new class image, return it back as "the" * new class image. This must be JVMTI Allocate space. */ if ( newLength > 0 ) { unsigned char *jvmti_space; jvmti_space = (unsigned char *)allocate(jvmti, (jint)newLength); (void)memcpy((void*)jvmti_space, (void*)newImage, (int)newLength); *new_class_data_len = (jint)newLength; *new_class_data = jvmti_space; /* VM will deallocate */ } /* Always free up the space we get from java_crw_demo() */ if ( newImage != NULL ) { (void)free((void*)newImage); /* Free malloc() space with free() */ } } (void)free((void*)classname); } } exitCriticalSection(jvmti); }
/* Allocate memory and set function pointers */ static int af_open(struct af_instance* af) { int i; af_hrtf_t *s; float fc; af->control = control; af->uninit = uninit; af->filter_frame = filter; s = af->priv; s->dlbuflen = DELAYBUFLEN; s->hrflen = HRTFFILTLEN; s->basslen = BASSFILTLEN; s->cyc_pos = s->dlbuflen - 1; /* With a full (two axis) steering matrix decoder, s->matrix_mode should not be enabled lightly (it will also steer the Ls, Rs channels). */ s->matrix_mode = 0; s->decode_mode = HRTF_MIX_51; switch (s->mode) { case 0: /* Use matrix rear decoding. */ s->matrix_mode = 1; break; case 1: /* Input needs matrix decoding. */ s->decode_mode = HRTF_MIX_MATRIX2CH; break; case 2: s->matrix_mode = 0; break; } s->print_flag = 1; if (allocate(s) != 0) { MP_ERR(af, "Memory allocation error.\n"); return AF_ERROR; } for(i = 0; i < s->dlbuflen; i++) s->lf[i] = s->rf[i] = s->lr[i] = s->rr[i] = s->cf[i] = s->cr[i] = 0; s->lr_fwr = s->rr_fwr = 0; s->cf_ir = cf_filt + (s->cf_o = pulse_detect(cf_filt)); s->af_ir = af_filt + (s->af_o = pulse_detect(af_filt)); s->of_ir = of_filt + (s->of_o = pulse_detect(of_filt)); s->ar_ir = ar_filt + (s->ar_o = pulse_detect(ar_filt)); s->or_ir = or_filt + (s->or_o = pulse_detect(or_filt)); s->cr_ir = cr_filt + (s->cr_o = pulse_detect(cr_filt)); if((s->ba_ir = malloc(s->basslen * sizeof(float))) == NULL) { MP_ERR(af, "Memory allocation error.\n"); return AF_ERROR; } fc = 2.0 * BASSFILTFREQ / (float)af->data->rate; if(af_filter_design_fir(s->basslen, s->ba_ir, &fc, LP | KAISER, 4 * M_PI) == -1) { MP_ERR(af, "Unable to design low-pass " "filter.\n"); return AF_ERROR; } for(i = 0; i < s->basslen; i++) s->ba_ir[i] *= BASSGAIN; return AF_OK; }
void ofPixels_<PixelType>::allocate(size_t w, size_t h, ofImageType type){ allocate(w,h,ofPixelFormatFromImageType(type)); }
void ofPixels_<PixelType>::allocate(size_t w, size_t h, size_t _channels){ allocate(w,h,pixelFormatFromNumChannels(_channels)); }
void ofPixels_<PixelType>::setFromPixels(const PixelType * newPixels, size_t w, size_t h, ofPixelFormat format){ allocate(w,h,format); memcpy(pixels, newPixels, getTotalBytes()); }
void nemo_main() { stream instr, outstr; int i, n, naxis1, naxis2, naxis[2], moment; double edges[2]; struct fits_header fh; struct my_table_header r; char *record, *cp, mesg[80]; string *hitem; FITS *map; /* Setup */ instr = stropen(getparam("in"),"r"); /* open input */ moment = getiparam("moment"); if (moment < 1 || moment > 2) error("moment must be 1 or 2"); band = getiparam("band"); if (band < 1 || band > 10) { band = band_id(getdparam("band")); if (band < 1) error("Invalid DIRBE band"); } naxis[0] = nlon = getiparam("nlong"); naxis[1] = nlat = getiparam("nlat"); grid = (entryptr *) allocate(nlat*nlon*sizeof(entryptr)); for (i=0; i<nlat*nlon; i++) grid[i] = NULL; cp = getparam("coord"); switch (*cp) { case 'g': gal_coord = TRUE; break; case 'e': gal_coord = FALSE; break; default: error("Bad coordinate system choosen; try gal or ecl"); } if (nemoinpd(getparam("long"),edges,2) != 2) error("long= needs 2 values"); if (edges[0] <= edges[1]) error("long= needs left edge to be largest"); lonmin = edges[0]; lonmax = edges[1]; dlon = (lonmax-lonmin)/(float)nlon; if (nemoinpd(getparam("lat"),edges,2) != 2) error("lat= needs 2 values"); if (edges[0] >= edges[1]) error("lat= needs right edge to be largest"); latmin = edges[0]; latmax = edges[1]; dlat = (latmax-latmin)/(float)nlat; dprintf(1,"GridSize: %d * %d Pixels: %g * %g\n",nlon,nlat,dlon,dlat); gc_middle = (lonmax < 0.0 && lonmin > 0.0); /* see if to use SYM_ANGLE */ ncell = getiparam("ncell"); sigma2 = 2*sqr(getdparam("sigma")); /* Open output FITS file, and write a small yet descriptive enough header */ map = fitopen(getparam("out"),"new",2,naxis); fitwrhda(map,"CTYPE1", gal_coord ? "GLON" : "ELON"); fitwrhdr(map,"CRPIX1",(float) 1.0); /* should use center */ fitwrhdr(map,"CRVAL1",(float) (lonmin + 0.5 * dlon)); fitwrhdr(map,"CDELT1",(float) dlon); fitwrhda(map,"CTYPE2", gal_coord ? "GLAT" : "ELAT"); fitwrhdr(map,"CRPIX2",(float) 1.0); /* should use center */ fitwrhdr(map,"CRVAL2",(float) (latmin + 0.5 * dlat)); fitwrhdr(map,"CDELT2",(float) dlat); fitwrhda(map,"TELESCOP","COBE"); fitwrhda(map,"INSTRUME","DIRBE"); fitwrhda(map,"ORIGIN","NEMO processing on CDAC data"); fitwrhda(map,"BUNIT","MJy/sr"); sprintf(mesg,"NEMO: %s VERSION=%s",getargv0(),getparam("VERSION")); fitwra(map,"HISTORY", mesg); hitem = ask_history(); fitwra(map,"HISTORY","NEMO: History in reversed order"); for (i=0, cp=hitem[0]; cp != NULL; i++) { fitwral(map,"HISTORY",cp); cp = hitem[i+1]; /* point to next history item */ } /* Open input file, and process all rows */ fts_zero(&fh); /* clean out header */ n = fts_rhead(&fh,instr); /* read primary header */ if (n<0) error("Error reading primary HDU"); fts_sdata(&fh,instr); /* and skip data .. */ fts_zero(&fh); /* clean out header */ n = fts_rhead(&fh,instr); /* read primary header */ if (n<0) error("Error reading second HDU"); naxis1 = fh.naxisn[0]; /* size of one row */ naxis2 = fh.naxisn[1]; /* number of rows */ record = allocate(naxis1); for (i=0; i<naxis2; i++) { /* loop reading rows */ n = fread(record,1,naxis1,instr); if (n != naxis1) error("Early EOF on record %d",i+1); stuffit(&fh,record,&r); } printf("Used %d/%d points in gridding\n",nused,naxis2); /* map the data on a grid */ mapit(map,moment); /* finish off */ fitclose(map); strclose(instr); }
int initFileSystem( unsigned int sectorSize, unsigned int blockSize, unsigned int totalSize) { unsigned int numSectors; unsigned int numBlocks; int retval; if (blockSize % sectorSize != 0) { return ERROR_BAD_GEOMETRY; } numBlocks = totalSize / blockSize; numSectors = totalSize / sectorSize; if (numBlocks > blockSize * 8) { return ERROR_BAD_GEOMETRY; } retval = allocate(totalSize, 0, &fileSystem); if (retval == EINVAL) { return ERROR_BAD_SIZE; } if (retval != 0) { return ERROR_BAD_GEOMETRY; } // if we got here, we have a suitable block of memory bzero(fileSystem, totalSize); // put the masterBlocks into the first block of the filesystem masterBlocks = (mbStructType *)fileSystem; masterBlocks->mblock0.inUse = 1; masterBlocks->mblock0.totalSize = totalSize; masterBlocks->mblock0.blockSize = blockSize; masterBlocks->mblock0.totalBlocks = numBlocks; masterBlocks->mblock0.rootDirBlock = 2; masterBlocks->mblock0.freeListBlock = 1; #ifdef PATCHED_1 masterBlocks->mblock0.dirEntriesPerBlock = (blockSize - 8)/sizeof(directoryEntryType); #else masterBlocks->mblock0.dirEntriesPerBlock = blockSize /sizeof(directoryEntryType); #endif masterBlocks->mblock0.blockEntriesPerCatalog = (blockSize - 8) / sizeof(int); masterBlocks->mblock0.checkValue = 0; // unused for now // mblock1 and mblock2 unused for now // and the freelist in the second block of the filesystem freeList = (unsigned char *)(fileSystem + blockSize); // and the root directory to the third rootDir = (rootDirType *)(fileSystem + (blockSize * 2)); // make sure these blocks are marked as in use setBlockInUse(0); // master block setBlockInUse(1); // free list block setBlockInUse(2); // root directory // now setup the root directory // calculate the max number of entries given the size of a block, minus the space for a link to the next block rootDir->maxEntries = (blockSize - 8)/sizeof(directoryEntryType); rootDir->numEntries = 0; bzero( fileCursors, sizeof(fileCursors)); return NO_ERROR; }
void* FixedAllocator::tryAllocate(size_t size) { return allocate(size); }
afs_atomlist * afs_atomlist_create(size_t atom_size, size_t block_size, void *(*allocate) (size_t n) , void (*deallocate) (void *p, size_t n) ) { afs_atomlist *al; size_t atoms_per_block; size_t extra_space; /* * Atoms must be at least as big as a pointer in order for * our implementation of the atom free list to work. */ if (atom_size < sizeof(void *)) { atom_size = sizeof(void *); } /* * Atoms must be a multiple of the size of a pointer * so that the pointers in the atom free list will be * properly aligned. */ if (atom_size % sizeof(void *) != (size_t) 0) { size_t pad = sizeof(void *) - (atom_size % sizeof(void *)); atom_size += pad; } /* * Blocks are the unit of memory allocation. * * 1) Atoms are allocated out of blocks. * * 2) sizeof(void *) bytes in each block, aligned on a sizeof(void *) * boundary, are used to chain together the blocks so that they can * be freed later. This reduces the space in each block for atoms. * It is intended that atoms should be small relative to the size of * a block, so this should not be a problem. * * At a minimum, a block must be big enough for one atom and * a pointer to the next block. */ if (block_size < atom_size + sizeof(void *)) return 0; atoms_per_block = block_size / atom_size; extra_space = block_size - (atoms_per_block * atom_size); if (extra_space < sizeof(void *)) { if (atoms_per_block < (size_t) 2) { return 0; /* INTERNAL ERROR! */ } atoms_per_block--; } al = allocate(sizeof *al); if (!al) return 0; al->atom_size = atom_size; al->block_size = block_size; al->allocate = allocate; al->deallocate = deallocate; al->atom_head = 0; al->block_head = 0; al->atoms_per_block = atoms_per_block; return al; }
ossimRefPtr<ossimImageData> ossimClosestToCenterCombiner::getTile(const ossimIrect& rect, ossim_uint32 resLevel) { ossim_uint32 layerIdx = 0; if(!isSourceEnabled()) { return ossimImageMosaic::getTile(rect, resLevel); } if(!theTile.valid()) { allocate(); if(!theTile.valid()) { return 0; } } theTile->setImageRectangle(rect); theTile->makeBlank(); std::vector<ossimClosestToCenterCombinerInfo > normTileList; ossimRefPtr<ossimImageData> currentTile = getNextNormTile(layerIdx, 0, rect); while(currentTile.valid()) { normTileList.push_back(ossimClosestToCenterCombinerInfo((ossimImageData*)currentTile->dup(), layerIdx)); currentTile = getNextNormTile(layerIdx, rect, resLevel); } if(normTileList.size() == 1) { theTile->copyNormalizedBufferToTile((ossim_float32*)normTileList[0].theTile->getBuf()); } else if(normTileList.size() > 1) { ossimRefPtr<ossimImageData> copyTile = ossimImageDataFactory::instance()->create(0, OSSIM_NORMALIZED_FLOAT); copyTile->setImageRectangleAndBands(rect, getNumberOfOutputBands()); copyTile->initialize(); ossim_int32 idx = 0; ossim_uint32 w = rect.width(); ossim_uint32 h = rect.height(); ossim_uint32 idxW = 0; ossim_uint32 idxH = 0; ossimIpt origin = rect.ul(); ossimIpt ulPt = rect.ul(); ossim_uint32 band = 0; ossim_uint32 bands = copyTile->getNumberOfBands(); ossim_uint32 srcBandIdx = 0; std::vector<ossim_float32*> bandList(bands); for(band = 0; band < bands; ++band) { bandList[band] = (ossim_float32*)copyTile->getBuf(band); } ossim_uint32 offset = 0; origin.y = ulPt.y; for(idxH = 0; idxH < h; ++idxH) { origin.x = ulPt.x; for(idxW = 0; idxW < w;++idxW) { idx = findIdx(normTileList, origin, offset); if(idx >=0) { ossim_uint32 tileBands = normTileList[idx].theTile->getNumberOfBands(); if (tileBands > 0) { tileBands -= 1; for(band = 0; band < bands; ++band) { srcBandIdx = ossim::min( tileBands, band ); bandList[band][offset] = *(((ossim_float32*)normTileList[idx].theTile->getBuf(srcBandIdx))+offset); } } } ++offset; ++origin.x; } ++origin.y; } theTile->copyNormalizedBufferToTile((ossim_float32*)copyTile->getBuf()); } theTile->validate(); return theTile; }
local void makedisk() { Body *bp; int i, nzero=0; real mdsk_i, rad_i, theta_i, vcir_i, omega, Aoort, kappa; real mu, sig_r, sig_t, sig_z, vrad_i, veff_i, vorb_i; real z1; static bool first = TRUE; disktab = (Body *) allocate(ndisk * sizeof(Body)); for (bp = disktab, i = 0; i < ndisk; bp++, i++) { Mass(bp) = mdsk[NTAB-1] / ndisk; mdsk_i = mdsk[NTAB-1] * ((real) i + 1.0) / ndisk; rad_i = seval(mdsk_i, &mdsk[0], &rdsk[0], &rdsk[NTAB], NTAB); theta_i = xrandom(0.0, TWO_PI); Pos(bp)[0] = rad_i * sin(theta_i); /* assign positions */ Pos(bp)[1] = rad_i * cos(theta_i); if (zmode==0) Pos(bp)[2] = grandom(0.0, 0.5 * z0); /* gauss */ else if (zmode==1) { z1 = xrandom(-1.0,1.0); Pos(bp)[2] = log(1-ABS(z1)) * z0; /* exp */ if (z1<0) Pos(bp)[2] = -Pos(bp)[2]; } else if (zmode==2) { z1 = frandom(0.0,10.0,mysech2) * z0; /* sech^2 */ if (xrandom(-1.0,1.0) < 0) z1 = -z1; Pos(bp)[2] = z1; } else if (zmode==3) { z1 = frandom(0.0,10.0,myexp) * z0; /* exp */ if (xrandom(-1.0,1.0) < 0) z1 = -z1; Pos(bp)[2] = z1; } else error("zmode=%d not supported yet",zmode); vcir_i = seval(rad_i, &rcir[0], &vcir[0], &vcir[NTAB], NTAB); omega = vcir_i / rad_i; Aoort = - 0.5 * (spldif(rad_i, &rcir[0], &vcir[0], &vcir[NTAB], NTAB) - omega); if (omega - Aoort < 0.0) printf("rad_i, omega, Aoort = %f %f %f\n", rad_i, omega, Aoort); kappa = 2 * sqrt(omega*omega - Aoort * omega); mu = alpha*alpha * mdisk * exp(- alpha * rad_i) / TWO_PI; if (cmode==1) { /* Straight from Josh - mkbaredisk*/ sig_r = 3.358 * Qtoomre * mu / kappa; sig_t = 0.5 * sig_r * kappa / omega; sig_z = 0.5 * sig_r; } else if (cmode==2) { sig_z = sqrt(PI * mu * z0); /* isothermal sech sheet */ sig_r = 2.0 * sig_z; /* with constant scaleheight */ Qtoomre = sig_r * kappa / (3.358 * mu); /* See vdKruit/Searle */ sig_t = 0.5 * sig_r * kappa / omega; } else error("illegal mode=%d",cmode); vrad_i = grandom(0.0, sig_r); if (gammas > 0.0) /* Josh' method: averaged */ veff_i = (vcir_i*vcir_i + (gammas - 3*alpha*rad_i) * sig_r*sig_r); else /* a little more accurate ? */ veff_i = sqr(vcir_i) - sqr(sig_r) * (sqr(sig_t/sig_r) - 1.5 + 0.5*sqr(sig_z/sig_r) + 2*alpha*rad_i); if (veff_i < 0.0) { nzero++; veff_i = 0.0; } else veff_i = sqrt(veff_i); vorb_i = veff_i + grandom(0.0, sig_t); Vel(bp)[0] = /* assign velocities */ (vrad_i * Pos(bp)[0] + vorb_i * Pos(bp)[1]) / rad_i; Vel(bp)[1] = (vrad_i * Pos(bp)[1] - vorb_i * Pos(bp)[0]) / rad_i; Vel(bp)[2] = grandom(0.0, sig_z); if (Qtab) { if (first) { first = FALSE; printf ("# R M V_circ Ome Kap Aoort mu sig_r sig_t sig_z v_eff Qtoomre sig_t/sig_r sig_z/sig_r fac\n"); } printf ("%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g\n", rad_i,mdsk_i,vcir_i,omega,kappa,Aoort,mu,sig_r,sig_t,sig_z,veff_i, Qtoomre, sig_t/sig_r,sig_z/sig_r, 1.5-(sqr(sig_t) + 0.5*sqr(sig_z))/sqr(sig_r) ); } } if (nzero) dprintf(0,"Warning: %d stars with too little orbital motion\n",nzero); if (getbparam("zerocm")) centersnap(disktab, ndisk); }
/** * Tests the integer array. */ void test_integer_array() { log_write_terminated_message((void*) stdout, L"Test integer array:\n"); // The test value (for the "decode" function below). wchar_t* test = L"2,3,4"; int testc = *NUMBER_5_INTEGER_MEMORY_MODEL; // The test knowledge model. int* m = (int*) *NULL_POINTER_MEMORY_MODEL; int* mc = (int*) *NULL_POINTER_MEMORY_MODEL; int* ms = (int*) *NULL_POINTER_MEMORY_MODEL; // Allocate test knowledge model. allocate((void*) &mc, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); *mc = *NUMBER_0_INTEGER_MEMORY_MODEL; allocate((void*) &ms, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); *ms = *NUMBER_0_INTEGER_MEMORY_MODEL; allocate((void*) &m, (void*) ms, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); fwprintf(stdout, L"pre mc: %i\n", *mc); fwprintf(stdout, L"pre ms: %i\n", *ms); fwprintf(stdout, L"pre m: %i\n", *m); // // Use either the "decode" function or the three "set" functions below. // Both possibilities should have the same functionality and results. // /*?? // Decode (parse) test value and assign to test knowledge model. decode((void*) &m, (void*) mc, (void*) ms, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, (void*) test, (void*) &testc, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); */ /*?? TODO! // Set test values. overwrite_array((void*) &m, (void*) mc, (void*) ms, (void*) NUMBER_2_INTEGER_MEMORY_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) mc, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); overwrite_array((void*) &m, (void*) mc, (void*) ms, (void*) NUMBER_3_INTEGER_MEMORY_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) mc, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); overwrite_array((void*) &m, (void*) mc, (void*) ms, (void*) NUMBER_4_INTEGER_MEMORY_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) mc, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); */ // The result values read out from the integer vector. int* result0 = (int*) *NULL_POINTER_MEMORY_MODEL; int* result1 = (int*) *NULL_POINTER_MEMORY_MODEL; int* result2 = (int*) *NULL_POINTER_MEMORY_MODEL; // Get result values. get((void*) &result0, m, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); get((void*) &result1, m, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); get((void*) &result2, m, (void*) NUMBER_2_INTEGER_MEMORY_MODEL, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); fwprintf(stdout, L"post mc: %i\n", *mc); fwprintf(stdout, L"post ms: %i\n", *ms); fwprintf(stdout, L"post m: %i\n", *m); fwprintf(stdout, L"post result0: %i\n", *result0); fwprintf(stdout, L"post result1: %i\n", *result1); fwprintf(stdout, L"post result2: %i\n", *result2); // Deallocate test knowledge model. deallocate((void*) &m, (void*) ms, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); deallocate((void*) &mc, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); deallocate((void*) &ms, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); }
/** * string::string(const char *) */ string::string(const char *array) : length{ strlen(array)} { allocate(); strcpy( strBuf, array); }
void get_dyld_state_symbols( void) { unsigned long i, j, save_nname, ncmds; struct ofile *ofiles; struct load_command *lc; struct segment_command *sg; struct segment_command_64 *sg64; struct symtab_command *st; struct nlist *symbols; struct nlist_64 *symbols64; if(image_count == 0) return; /* * Create an ofile for each image. */ ofiles = allocate(image_count * sizeof(struct ofile)); for(i = 0; i < image_count; i++){ if(ofile_map(dyld_images[i].name, &host_arch_flag, NULL, ofiles + i, FALSE) == 0) fatal("ofile_map() failed"); if(ofiles[i].mh == NULL && ofiles[i].mh64 == NULL) fatal("file from dyld loaded state: %s is not a Mach-O file", dyld_images[i].name); } /* * Pass 1 count symbols */ save_nname = nname; for(i = 0; i < image_count; i++){ st = NULL; lc = ofiles[i].load_commands; if(ofiles[i].mh != NULL) ncmds = ofiles[i].mh->ncmds; else ncmds = ofiles[i].mh64->ncmds; for(j = 0; j < ncmds; j++){ if(st == NULL && lc->cmd == LC_SYMTAB){ st = (struct symtab_command *)lc; if(ofiles[i].mh != NULL){ symbols = (struct nlist *) (ofiles[i].object_addr + st->symoff); symbols64 = NULL; } else{ symbols64 = (struct nlist_64 *) (ofiles[i].object_addr + st->symoff); symbols = NULL; } count_func_symbols(symbols, symbols64, st->nsyms, ofiles[i].object_addr + st->stroff, st->strsize); } if(dyld_images[i].image_header != 0 && dyld_images[i].vmaddr_slide == 0){ if(lc->cmd == LC_SEGMENT){ sg = (struct segment_command *)lc; if(sg->filesize != 0){ dyld_images[i].vmaddr_slide = dyld_images[i].image_header - sg->vmaddr; } } else if(lc->cmd == LC_SEGMENT_64){ sg64 = (struct segment_command_64 *)lc; if(sg64->filesize != 0){ dyld_images[i].vmaddr_slide = dyld_images[i].image_header - sg64->vmaddr; } } } lc = (struct load_command *)((char *)lc + lc->cmdsize); } } /* * Reallocate the data structures for the symbols. */ nl = (nltype *)realloc(nl, (nname + 1) * sizeof(nltype)); if(nl == NULL) fatal("No room for %lu bytes of symbol table\n", (nname + 1) * sizeof(nltype)); npe = nl + (save_nname + 1); memset(npe, '\0', (nname - save_nname) * sizeof(nltype)); /* * Pass 2 load symbols. */ for(i = 0; i < image_count; i++){ st = NULL; lc = ofiles[i].load_commands; if(ofiles[i].mh != NULL) ncmds = ofiles[i].mh->ncmds; else ncmds = ofiles[i].mh64->ncmds; for(j = 0; j < ncmds; j++){ if(st == NULL && lc->cmd == LC_SYMTAB){ st = (struct symtab_command *)lc; if(ofiles[i].mh != NULL){ symbols = (struct nlist *) (ofiles[i].object_addr + st->symoff); symbols64 = NULL; } else{ symbols64 = (struct nlist_64 *) (ofiles[i].object_addr + st->symoff); symbols = NULL; } load_func_symbols(symbols, symbols64, st->nsyms, ofiles[i].object_addr + st->stroff, st->strsize, dyld_images[i].vmaddr_slide); } lc = (struct load_command *)((char *)lc + lc->cmdsize); } } #ifdef DEBUG if(debug & DYLDDEBUG){ for(i = save_nname + 1; i < nname + 1; i++){ printf("[get_dyld_state_symbols] "); if(ofiles[0].mh != NULL) printf("0x%08x", (unsigned int)nl[i].value); else printf("%016llx", nl[i].value); printf("\t%s\n", nl[i].name); } } #endif /* DEBUG */ /* * Resort the symbol table. */ qsort(nl, nname + 1, sizeof(nltype), (int (*)(const void *, const void *))valcmp); free(ofiles); }
string::string( string const& rhs) : length{rhs.length} { allocate(); strcpy( strBuf, rhs.strBuf); }
void ofGstVideoPlayer::on_stream_prepared(){ if(!bIsAllocated) allocate(); }
/* * NAME: open() * DESCRIPTION: open the connection */ static void open() { ::open(allocate(driver->query_tls_size())); }
void* operator new[](std::size_t n) { return allocate(n); }
/* * NAME: close() * DESCRIPTION: close the connection */ static void close(int dest) { ::close(allocate(driver->query_tls_size()), dest); }
/** @PageName list_array @PageTitle Basic array operations @PageFather list @FuncTitle Setting an element @FuncDesc You can assign a value with set. If needed, the array will allocate new elements up to idx. @Cpp template <class T> void TCODList::set(const T elt, int idx) @C void TCOD_list_set(TCOD_list_t l,const void *elt, int idx) @Param elt Element to put in the array. @Param idx Index of the element. 0 <= idx @Param l In the C version, the handler, returned by a constructor. @CppEx TCODList<int> intList; // the array is empty (contains 0 elements) intList.set(5,0); // the array contains 1 element at position 0, value = 5 intList.set(7,2); // the array contains 3 elements : 5, 0, 7 @CEx TCOD_list_t intList = TCOD_list_new(); TCOD_list_set(intList,(const void *)5,0); TCOD_list_set(intList,(const void *)7,2); */ void set(const T elt, int idx) { if ( idx < 0 ) return; while ( allocSize < idx+1 ) allocate(); array[idx] = elt; if ( idx+1 > fillSize ) fillSize = idx+1; }
void ofPixels_<PixelType>::setFromPixels(const PixelType * newPixels, size_t w, size_t h, size_t channels){ allocate(w, h, channels); memcpy(pixels, newPixels, getTotalBytes()); }