Changeset 390 for soft/giet_vm/giet_libs/malloc.c
- Timestamp:
- Aug 7, 2014, 4:57:07 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_libs/malloc.c
r382 r390 78 78 } 79 79 80 // compute alloc[] minimal array size80 // compute size of block containin alloc[] array 81 81 alloc_size = heap_size / MIN_BLOCK_SIZE; 82 if ( alloc_size < MIN_BLOCK_SIZE) alloc_size = MIN_BLOCK_SIZE; 82 83 83 84 // get index for the corresponding block … … 98 99 unsigned int base = heap_base; 99 100 unsigned int* ptr; 100 for ( index = heap_index-1 ; index > alloc_index ; index-- )101 for ( index = heap_index-1 ; index >= alloc_index ; index-- ) 101 102 { 102 103 heap[x][y].free[index] = base; … … 247 248 } 248 249 250 // normalize size 251 if ( size < MIN_BLOCK_SIZE ) size = MIN_BLOCK_SIZE; 252 249 253 // compute requested_index for the free[] array 250 254 unsigned int requested_index = GET_SIZE_INDEX( size ); … … 258 262 requested_index ); 259 263 260 // update the alloc[] array 261 unsigned offset = (base - heap[x][y].heap_base) / MIN_BLOCK_SIZE; 262 unsigned char* ptr = (unsigned char*)(heap[x][y].alloc_base + offset); 263 *ptr = requested_index; 264 // update the alloc[] array if block found 265 if ( base != 0 ) 266 { 267 unsigned offset = (base - heap[x][y].heap_base) / MIN_BLOCK_SIZE; 268 unsigned char* ptr = (unsigned char*)(heap[x][y].alloc_base + offset); 269 *ptr = requested_index; 270 } 264 271 265 272 // release the lock … … 286 293 void free( void* ptr ) 287 294 { 288 // To be done 289 // - first : to compute the cluster coordinate 290 // - second : retrieve the block length from the 291 // - third : try to concatenate with another free block of same size 292 // - fourth : update the free[] array 295 unsigned int vaddr = (unsigned int)ptr; 296 297 // get the cluster coordinate 298 unsigned int x; 299 unsigned int y; 300 giet_get_xy( ptr, &x, &y ); 301 302 // compute index in alloc[] array 303 unsigned index = ( (unsigned int)ptr - heap[x][y].heap_base ) / MAX_BLOCK_SIZE; 304 305 // get the freed block size_index 306 unsigned char* p i = (unsigned char*)(heap[x][y].alloc_base + index); 307 unsigned int size_index = (unsigned int)*p; 308 309 // update the free[] array and NEXT pointer 310 *(unsigned int*)ptr = heap[x][y].free[size_index]; 311 heap[x][y].free[size_index] = (unsigned int)ptr; 312 313 // TODO try to concatenate with another free block of same size 314 // this require probably to replace this simple push by a recursive function 293 315 } 294 316
Note: See TracChangeset
for help on using the changeset viewer.