void FftConvolver::setResponse(int length, float* newResponse) { int neededLength= kiss_fftr_next_fast_size_real (block_size+length); int newTailSize=neededLength-block_size; if(neededLength !=fft_size || tail_size !=newTailSize) { if(workspace) freeArray(workspace); workspace=allocArray<float>(neededLength); if(tail) freeArray(tail); tail=allocArray<float>(newTailSize); fft_size=neededLength/2+1; workspace_size=neededLength; tail_size=newTailSize; if(fft) kiss_fftr_free(fft); fft = kiss_fftr_alloc(workspace_size, 0, nullptr, nullptr); if(ifft) kiss_fftr_free(ifft); ifft=kiss_fftr_alloc(workspace_size, 1, nullptr, nullptr); if(response_fft) freeArray(response_fft); response_fft=allocArray<kiss_fft_cpx>(fft_size); if(block_fft) freeArray(block_fft); block_fft=allocArray<kiss_fft_cpx>(fft_size); } memset(workspace, 0, sizeof(float)*workspace_size); memset(tail, 0, sizeof(float)*tail_size); //Store the fft of the response. std::copy(newResponse, newResponse+length, workspace); kiss_fftr(fft, workspace, response_fft); }
void mainLoop(const char* configFile, int generations) { // need a pair of arrays, one to hold grid and the other to hold updates //(unless we invent a more complex datastructure/algorithm to allow in-place // modification of the array) ARRAY2D arrays[2] = {0}; // keep track of which array is active, the other is used for updates int active = 0; int i; // bounds on the rows this node handles int upper, lower; setupArrays(configFile, arrays, &upper, &lower); // loop over number of generations for(i = 0; i < generations; i++) { display(arrays[active], i); // calculate updates timestep(arrays[active], arrays[!active], lower, upper); // swap arrays active = !active; updateOtherProcesses(upper, lower, arrays[active]); } display(arrays[active], i); // cleanup freeArray(arrays[0]); freeArray(arrays[1]); }
void PoiseuilleFlowSystem::_finalize(){ assert(IsInitialized); delete [] hPos; delete [] hVel; delete [] hVelLeapFrog; delete [] hMeasures; delete [] hAcceleration; freeArray(dVel); freeArray(dVelLeapFrog); freeArray(dMeasures); freeArray(dAcceleration); freeArray(dSortedPos); freeArray(dSortedVel); freeArray(dHash); freeArray(dIndex); freeArray(dCellStart); freeArray(dCellEnd); if (IsOpenGL) { unregisterGLBufferObject(cuda_posvbo_resource); glDeleteBuffers(1, (const GLuint*)&posVbo); glDeleteBuffers(1, (const GLuint*)&colorVBO); } else { checkCudaErrors( cudaFree(cudaPosVBO) ); checkCudaErrors( cudaFree(cudaColorVBO) ); } }
Node::~Node() { for(auto i: output_buffers) { if(i) freeArray(i); } for(auto i: input_buffers) { if(i) freeArray(i); } simulation->invalidatePlan(); }
int main (int argc, char *argv[]) { array* a = initArray (7, 5); array* b = initArray (7, 5); playGame (a, b); freeArray (a); freeArray (b); return 0; }
/* olusturulan thread e gonderilern void pointer fonksiyon */ void* threadOperation(void* data) { sem_wait(&sem);/*mutex locked*/ clock_t start; double duration; start = clock(); char *szFullName=(char*)data; int boyutX,boyutY,total; char **arr,**words; int fdx; /*total words sayisi bulunup toplama a eklenir*/ printf("Thread_id: %lu\n", pthread_self()); boyutX= getLineNum(data); //printf(" line %d\n",boyutX); boyutY = getBoyut(data); arr=Make2DintArray(boyutX+1,boyutY+1); /*dosya okunur */ readData(data,arr,boyutX); total=countWordsInArray(arr,boyutX); /* Thread resource lari geri birakilir */ totalWords=totalWords+total; fprintf(stderr,"%s inside total words %d\n",(char*)data,total); readData(data,arr,boyutX); words = readWords(arr,boyutX,total); addWordsFile(words,total); freeArray(arr,boyutX+1); freeArray(words,total); //pthread_detach(pthread_self()); duration = ( clock() - start ) / (double) CLOCKS_PER_SEC; printf("duration time is %f\n",duration); sem_post(&sem);/*mutex acilir*/ //pthread_exit(NULL); return NULL; }
void ParticleSystem::_finalize(){ assert(m_bInitialized); free(m_hPos); free(m_hVel); free(m_hCellStart); free(m_hCellEnd); free(m_hReorderedVel); free(m_hReorderedPos); free(m_hIndex); free(m_hHash); freeArray(m_dPos); freeArray(m_dVel); freeArray(m_dReorderedPos); freeArray(m_dReorderedVel); freeArray(m_dHash); freeArray(m_dIndex); freeArray(m_dCellStart); freeArray(m_dCellEnd); if (!m_bQATest) { unregisterGLBufferObject(m_posVbo); glDeleteBuffers(1, (const GLuint*)&m_posVbo); glDeleteBuffers(1, (const GLuint*)&m_colorVBO); } }
/** busca un rectángulo dentro del R-Tree. */ Dynamic_array* buscar(Nodo nodo, Rectangulo rect) { int i, j; Dynamic_array *rects; // arreglo dinámico de rectangulos initArray(rects, 1); // recorremos los MBR's del nodo for(i=0;i<=nodo.ultimo;i++) { // si el rectangulo se intersecta con un MBR if (interseccion(nodo.mbr[i].rect, rect)){ // si es una hoja. retornar rectangulo; if (nodo.mbr[i].nodo_hijo == -1) { insertArray(rects, nodo.mbr[i].rect); // seguir en profundidad } else { // buscar en los hijos Nodo nodo_hijo = leer_nodo_en_disco(nodo.mbr[i].nodo_hijo); Dynamic_array *rects_hijos = buscar(nodo_hijo, rect); // se insertan en el grupo general for(j=0;j<rects_hijos->used;j++) { insertArray(rects, rects_hijos->array[j]); } // se libera la memoria. freeArray(rects_hijos); } } } return rects; }
// Algorithm start int main(int argc, char **argv) { long int startPoint = 600851475143; // Starting point from project euler, you can change it Array primeFactors; // Our beautiful new Array for prime factors int maxPrimeFactor = 0; // Max, if founded. initArray(&primeFactors, 1); // Initialize empty array with size of one // Start the iteration while( startPoint > 1 ) { for( int i = 2; i <= startPoint; i++) { if( startPoint % i == 0) // If startPoint is divisible by i { startPoint = (startPoint / i); // Actually divide the starting Point insertArray(&primeFactors, i); // Inser the value inside our Array if( primeFactors.array[i] > maxPrimeFactor) // check if is the Max around here { maxPrimeFactor = primeFactors.array[i]; // If max, save it. } } } } freeArray(&primeFactors); // Release the ... memory return 0; // End of the algorithm }
int main(){ allocateArray(); fillArray(); printArray(); freeArray(); return 0; }
void ParticleMesh::release() { if (!par_list) delete[] par_list; if (!sdf_list) delete[] sdf_list; if (!mp_vertexXYZ) delete[] mp_vertexXYZ; if (!Relative_Vertex) delete[] Relative_Vertex; if (!FaceVerInd) delete[] FaceVerInd; if (!mp_vertexRGB) delete[] mp_vertexRGB; if (!mp_vertexNorm) delete[] mp_vertexNorm; if (!dRelative_Vertex) freeArray(dRelative_Vertex); unregisterGLBufferObject(m_cuda_indexvbo_resource); glDeleteBuffers(1, (const GLuint *)&m_indexVBO); unregisterGLBufferObject(m_cuda_normalvbo_resource); glDeleteBuffers(1, (const GLuint *)&m_NorVBO); unregisterGLBufferObject(m_cuda_colorvbo_resource); glDeleteBuffers(1, (const GLuint *)&m_colorVBO); unregisterGLBufferObject(m_cuda_vertexvbo_resource); glDeleteBuffers(1, (const GLuint *)&m_vertexVbo); }
HrtfData::~HrtfData() { if(temporary_buffer1) freeArray(temporary_buffer1); if(temporary_buffer2) freeArray(temporary_buffer2); if(hrirs == nullptr) return; //we never loaded one. for(int i = 0; i < elev_count; i++) { //The staticResamplerKernel allocates with new[], not allocArray. for(int j = 0; j < azimuth_counts[i]; j++) delete[] hrirs[i][j]; delete[] hrirs[i]; } delete[] hrirs; delete[] azimuth_counts; freeArray(fft_time_data); freeArray(fft_data); kiss_fftr_free(fft); kiss_fftr_free(ifft); }
void *space_runner(void *arg){ Runner_Arg *rarg = (Runner_Arg *) arg; int read; int fd_is_close; while(1){ // lock ; read file; int locked = pthread_mutex_lock(rarg->read_fd_lock); if (locked!=0) return error_lock("Could not lock on file : ", rarg->read_fd_lock); char *line = read_line_from_input(rarg->fd, &fd_is_close); if (!line){ if (fd_is_close){ pthread_mutex_unlock(rarg->read_fd_lock); //TODO - next step. return NULL; } return error_lock("Strange... could not allocate memory? : " , rarg->read_fd_lock); } if (pthread_mutex_unlock(rarg->read_fd_lock) != 0){ perror("Unlock :"); } char **arguments = split(line, &read); // Check arguments is clean: if (arguments == NULL ) return error_("Could not allocate in split of input line: "); if (read != 7 ){ fprintf(stderr, "Ignoring input line (!= %d): %s - ", read, line); freeArray(arguments); continue; } // return "add Education course C2 MI"; if (strcasecmp(arguments[2], "room")== 0){ if (read_room(rarg, arguments, read) != 0){ return error_(""); } else{ freeArray(arguments); continue; } } freeArray(arguments); //We got here. So we do not recognize this shit fprintf(stderr, "EntityType %s is not valid\n", arguments[2]); } }
void ParticleSystem::_finalize() { assert(m_bInitialized); delete [] m_hPos; delete [] m_hVel; delete [] m_hCellStart; delete [] m_hCellEnd; freeArray(m_dVel); freeArray(m_dSortedPos); freeArray(m_dSortedVel); freeArray(m_dGridParticleHash); freeArray(m_dGridParticleIndex); freeArray(m_dCellStart); freeArray(m_dCellEnd); if (m_bUseOpenGL) { unregisterGLBufferObject(m_cuda_colorvbo_resource); unregisterGLBufferObject(m_cuda_posvbo_resource); glDeleteBuffers(1, (const GLuint *)&m_posVbo); glDeleteBuffers(1, (const GLuint *)&m_colorVBO); } else { checkCudaErrors(cudaFree(m_cudaPosVBO)); checkCudaErrors(cudaFree(m_cudaColorVBO)); } }
void reallocArray(JNIEnv* env, int len ) { if ( _array==NULL || env->GetArrayLength(_array)<len ) { freeArray(env); jobject lref = env->NewIntArray(len); _array = (jintArray)env->NewGlobalRef( lref ); env->DeleteLocalRef(lref); } }
int main(void){ int *a[10]; int n = 10; int sum = mallocArray(a, n); printArray(a, sum); freeArray(a, sum); }
void destroyPlnWeights(struct PlnWeights *pln) { freeArray(pln->inputMeans); freeArray(pln->inputStd); /* cluster centers and distance measure */ freeArray(pln->distanceMeasure); freeMatrix(pln->clusterCenters, pln->Nc); /* cluster weights */ freeMatrix3(pln->W, pln->Nc, pln->M); /* Unused entries which can be left uninitialized */ freeArray((double*)pln->Nv); /* samples in each cluster */ freeMatrix3(pln->R, pln->Nc, pln->N+1); freeMatrix3(pln->C, pln->Nc, pln->M); freeMatrix(pln->Et, pln->Nc); /* variance of outputs */ freeArray(pln->lambda); /* regularization parameter */ }
int main(int argc, char *argv[]) { int *array; int width, height; int value; char **stringPtr; int **matrix; /* testing for part 1 */ printf("Testing Part 1\n"); width = 5; height = 6; array = create2DArray(height, width); printf("Store value 7 at [3,4].\n"); set2DElement(array, 3, 4, 7); value = get2DElement(array, 3, 4); printf("Retrieve value %d from [3,4]\n\n", value); free2DArray(array); /* testing for part 2 */ printf("Testing Part 2\n"); stringPtr = createStringArray(100); printf("Store string - fred\n"); setStringArray(stringPtr, 44, "fred"); printf("Store string - barney\n"); setStringArray(stringPtr, 80, "barney"); printf("Get string - %s\n", getStringArray(stringPtr, 44)); printf("Get string - %s\n", getStringArray(stringPtr, 80)); /* test with NULL string */ printf("Get string - %s\n\n", getStringArray(stringPtr, 3)); freeStringArray(stringPtr, 100); /* testing for part 3 */ printf("Testing Part 3\n"); matrix = createArray(100, 100); printf("Store 33 44 55\n"); matrix[22][76] = 33; matrix[83][29] = 44; matrix[99][65] = 55; printf("Retrieve %d %d %d\n", matrix[22][76], matrix[83][29], matrix[99][65]); freeArray(matrix, 100); return(1); }
/*it takes main arguments */ int main(int argc, char **argv) { /* 1. 2. argumanalr duzgun ve bos olmamali */ /* calistirilabilir dosya ile file name arasinda . */ if ((argv[1] == NULL) || (argv[2] == NULL) || argc!=3) { printf("Yanlis Kullanim\n"); printf("Dogru yazim sekli\n"); printf(" ./111044051Ramazan a.txt 11\n"); return(-1); } int boyutX,boyutY; /* max satir boyutu */ char **arr; boyutX= getLineNum(argv[1]); boyutY = getBoyut(argv[1]); if(atoi(argv[2])<1){ printf("Yanlis Kullanim linenumber birden kucuk olamaz\n"); return(-1); } int i=0,j=0; /* Donguler icin gerekli degiskenler. */ int lineNum; lineNum=atoi(argv[2]); //printf("lineNum = % d\n",lineNum); /* Hafizadan yer alinir. */ arr=Make2DintArray(boyutX+1,boyutY+1); /*dosya okunur */ readData(argv[1],arr,boyutX); /*more or less calisir*/ moreOrLess(arr,boyutX,lineNum); /*array yeri geri verilir*/ freeArray(arr,boyutX+1); //printf("\b"); //printf("\b\n"); return 0; }
void freeMatrix(double **ptr, int rows) { int r; if(ptr == NULL) { printf("Free on null pointer.\n\n"); exit(0); } for(r=0; r<rows; r++) { freeArray(ptr[r]); } free(ptr); }
void concatV(struct array * v0, struct array * * out) { struct array * v64 = NULL; uint32_t len65; struct array * v3 = NULL; struct array * v63 = NULL; uint32_t v55; uint32_t v56; struct array * e66 = NULL; uint32_t v58; len65 = getLength(v0); v64 = initArray(v64, sizeof(int32_t), 0); for (uint32_t v2 = 0; v2 < len65; v2 += 1) { v63 = at(struct array *,v0,v2); v55 = getLength(v64); v56 = getLength(v63); v3 = initArray(v3, sizeof(int32_t), (v55 + v56)); for (uint32_t v5 = 0; v5 < v55; v5 += 1) { at(int32_t,v3,v5) = at(int32_t,v64,v5); } for (uint32_t v8 = 0; v8 < v56; v8 += 1) { at(int32_t,v3,(v8 + v55)) = at(int32_t,v63,v8); } e66 = v64; v64 = v3; v3 = e66; } v58 = getLength(v64); *out = initArray(*out, sizeof(int32_t), v58); for (uint32_t v22 = 0; v22 < v58; v22 += 1) { at(int32_t,*out,v22) = at(int32_t,v64,v22); } freeArray(v64); freeArray(v3); freeArray(v63); }
int main() { int row, column; ElemType **matrixa, **matrixb, **matrixadd, **matrixtran; //矩阵 TSMatrix arraya, arrayb, arrayadd, arraytran; //三元组 while (scanf("%d%d", &row, &column) != EOF && row*column) { CreateMatrix(&matrixa, row, column); //随机生成矩阵A printf("正在生成稀疏矩阵......\nDone!\nA矩阵:\n"); PrintMatrix(matrixa, row, column); //输出矩阵 printf("A矩阵的三元组:\n"); //输出A的三元组 MatrixToArray(matrixa, &arraya, row, column); //矩阵A转换为三元组 freeMatrix(&matrixa, row); PrintArray(arraya); printf("A矩阵的转置矩阵(快速转置得到):\n"); transpose(arraya, &arraytran); ArrayToMatrix(arraytran, &matrixtran); freeArray(&arraytran); PrintMatrix(matrixtran, column, row); freeMatrix(&matrixtran, column); CreateMatrix(&matrixb, row, column); //随机生成矩阵B printf("正在生成稀疏矩阵......\nDone!\nB矩阵:\n"); PrintMatrix(matrixb, row, column); printf("B矩阵的三元组:\n"); MatrixToArray(matrixb, &arrayb, row, column); freeMatrix(&matrixb, row); PrintArray(arrayb); printf("C矩阵(C=A+B):\n"); AddMatrixArray(arraya, arrayb, &arrayadd); freeArray(&arraya); freeArray(&arrayb); ArrayToMatrix(arrayadd, &matrixadd); freeArray(&arrayadd); PrintMatrix(matrixadd, row, column); freeMatrix(&matrixadd, row); } return 0; }
void *staff_runner(void *arg){ Runner_Arg *rarg = (Runner_Arg *) arg; int read; int fd_is_close; while(1){ // lock ; read file; int locked = pthread_mutex_lock(rarg->read_fd_lock); if (locked!=0) return error_lock("Could not lock on file : ", rarg->read_fd_lock); char *line = read_line_from_input(rarg->fd, &fd_is_close); if (!line){ if (fd_is_close){ pthread_mutex_unlock(rarg->read_fd_lock); //TODO - next step. return NULL; } return error_lock("Strange... could not allocate memory? : " , rarg->read_fd_lock); } if (pthread_mutex_unlock(rarg->read_fd_lock) != 0){ perror("Unlock :"); } char **arguments = split(line, &read); // Check arguments is clean: if (arguments == NULL ) return error_("Could not allocate in split of input line: "); if (read != 6 ){ fprintf(stderr, "Ignoring input line: %s | %d.", line, read); freeArray(arguments); continue; } //Create new Staff entity. if (strcasecmp(arguments[2], "teacher") == 0){ if (read_teacher(arg, arguments, read) != 0){ return NULL; } } else{ fprintf(stderr, "EntityType %s is not valid\n", arguments[2]); } freeArray(arguments); } }
//protected resize function. void Node::resize(int newInputCount, int newOutputCount) { int oldInputCount = input_buffers.size(); for(int i = oldInputCount-1; i >= newInputCount; i--) if(input_buffers[i]) freeArray(input_buffers[i]); input_buffers.resize(newInputCount, nullptr); for(int i = oldInputCount; i < newInputCount; i++) input_buffers[i] = allocArray<float>(simulation->getBlockSize()); int oldOutputCount = output_buffers.size(); if(newOutputCount < oldOutputCount) { //we need to free some arrays. for(auto i = newOutputCount; i < oldOutputCount; i++) { if(output_buffers[i]) freeArray(output_buffers[i]); } } //do the resize. output_buffers.resize(newOutputCount, nullptr); if(newOutputCount > oldOutputCount) { //we need to allocate some more arrays. for(auto i = oldOutputCount; i < newOutputCount; i++) { output_buffers[i] = allocArray<float>(simulation->getBlockSize()); } } }
LateReflectionsNode::~LateReflectionsNode() { freeArray(gains); freeArray(output_frame); freeArray(next_input_frame); freeArray(delays); freeArray(amplitude_modulation_buffer); for(int i=0; i < order; i++) { delete highshelves[i]; delete midshelves[i]; delete amplitude_modulators[i]; delete delay_modulators[i]; delete allpass_modulators[i]; delete pan_reducers[i]; } delete[] highshelves; delete[] midshelves; delete[] amplitude_modulators; delete[] delay_modulators; delete[] allpass_modulators; delete[] pan_reducers; }
int main(int argc, char * argv[]){ if (argc > 1) { getEncodeFlags(argc, argv); encode(); flushBits(); } else { decoding(); decode(); } freeArray(); return 1; }
void freeFontStorage() { if (fontSearchPaths != NULL) { // Clear the array and free the data while (fontSearchPaths->length > 0) { free(removeArray(fontSearchPaths, 0, False)); } freeArray(fontSearchPaths); free(fontSearchPaths); fontSearchPaths = NULL; } if (fontCache != NULL) { // Clear the array and free the data while (fontCache->length > 0) { FontCacheEntry* entry = removeArray(fontSearchPaths, 0, False); free(entry->filePath); free(entry->XLFName); free(entry); } freeArray(fontCache); free(fontCache); fontSearchPaths = NULL; } }
void metrics(struct array * v0, struct array * v1, struct array * v2, struct array * * out) { uint32_t v28; uint32_t v29; struct array * st32 = NULL; struct array * * v16 = NULL; struct array * v30 = NULL; uint32_t len33; v28 = getLength(v2); v29 = getLength(v0); st32 = initArray(st32, sizeof(int32_t), 8); at(int32_t,st32,0) = -32678; at(int32_t,st32,1) = -32678; at(int32_t,st32,2) = -32678; at(int32_t,st32,3) = -32678; at(int32_t,st32,4) = -32678; at(int32_t,st32,5) = -32678; at(int32_t,st32,6) = -32678; at(int32_t,st32,7) = -32678; v16 = &st32; *out = initArray(*out, (0 - sizeof(struct array *)), v28); for (uint32_t v15 = 0; v15 < v28; v15 += 1) { v30 = at(struct array *,v2,v15); len33 = min(getLength(v30), v29); at(struct array *,*out,v15) = initArray(at(struct array *,*out,v15), sizeof(int32_t), len33); for (uint32_t v17 = 0; v17 < len33; v17 += 1) { at(int32_t,at(struct array *,*out,v15),v17) = at(int32_t,*v16,(at(struct s_2_unsignedS32_unsignedS32,v30,v17)).member1); } v16 = &at(struct array *,*out,v15); } *out = initArray(*out, (0 - sizeof(struct array *)), v28); freeArray(st32); freeArray(v30); }
int main(int argc, char** argv){ if(argc!=3){//skontrolujeme vstupny pocet argumentov fprintf(stderr,"Zly pocet argumentov"); return 1; } FILE* f= NULL; f= fopen(argv[1],"r");//otvorime subor if(f==NULL){//skontrolujeme ci sa nam podarilo otvorit subor fprintf(stderr,"Nepodarilo sa otvorit subor"); return 1; } /*Nacitavanie cez zoznam aj s vypisom a mazanim pamate*//* list* records= NULL; records= malloc(sizeof(list)); if(records == NULL){ fprintf(stderr,"Nedostatok pamate!\n"); return 0; } records->end= NULL; records->start= NULL; int lines=0; if((lines=readLinesToLinkedList(f,records))==0){ printf("ziadnny riadok\n"); return 1; } node* current= records->start; printf("%s\n",current->data); while(current->pNext!=NULL){ current=current->pNext; printf("%s\n",current->data); } freeLinkedList(records);*/ /*nacitavanie cez pole aj s vypisom a mazanim pamate*/ char** records= NULL; int lines=0; if((lines=readLinesToArray(f,&records))==0){ printf("ziadnny riadok\n"); return 1; } for(int i=0;i<lines;i++){ printf("%s\n",records[i]); } freeArray(records,lines); return 0; }
Lav_PUBLIC_FUNCTION LavError Lav_bufferLoadFromFile(LavHandle bufferHandle, const char* path) { PUB_BEGIN auto buff =incomingObject<Buffer>(bufferHandle); FileReader f{}; f.open(path); float* data = allocArray<float>(f.getSampleCount()); f.readAll(data); { LOCK(*buff); buff->throwIfInUse(); buff->loadFromArray(f.getSr(), f.getChannelCount(), f.getSampleCount()/f.getChannelCount(), data); } freeArray(data); PUB_END }