Allocate continuous buffer of the specified size in the storage: */
| 314 | |
| 315 | /* Allocate continuous buffer of the specified size in the storage: */ |
| 316 | CV_IMPL void* |
| 317 | cvMemStorageAlloc( CvMemStorage* storage, size_t size ) |
| 318 | { |
| 319 | schar *ptr = 0; |
| 320 | if( !storage ) |
| 321 | CV_Error( CV_StsNullPtr, "NULL storage pointer" ); |
| 322 | |
| 323 | if( size > INT_MAX ) |
| 324 | CV_Error( CV_StsOutOfRange, "Too large memory block is requested" ); |
| 325 | |
| 326 | assert( storage->free_space % CV_STRUCT_ALIGN == 0 ); |
| 327 | |
| 328 | if( (size_t)storage->free_space < size ) |
| 329 | { |
| 330 | size_t max_free_space = cvAlignLeft(storage->block_size - sizeof(CvMemBlock), CV_STRUCT_ALIGN); |
| 331 | if( max_free_space < size ) |
| 332 | CV_Error( CV_StsOutOfRange, "requested size is negative or too big" ); |
| 333 | |
| 334 | icvGoNextMemBlock( storage ); |
| 335 | } |
| 336 | |
| 337 | ptr = ICV_FREE_PTR(storage); |
| 338 | assert( (size_t)ptr % CV_STRUCT_ALIGN == 0 ); |
| 339 | storage->free_space = cvAlignLeft(storage->free_space - (int)size, CV_STRUCT_ALIGN ); |
| 340 | |
| 341 | return ptr; |
| 342 | } |
| 343 | |
| 344 | |
| 345 | CV_IMPL CvString |
no test coverage detected