MCPcopy Create free account
hub / github.com/creatale/node-dv / icvGrowSeq

Function icvGrowSeq

deps/opencv/modules/core/src/datastructs.cpp:625–747  ·  view source on GitHub ↗

The function allocates space for at least one more sequence element. If there are free sequence blocks (seq->free_blocks != 0) they are reused, otherwise the space is allocated in the storage: */

Source from the content-addressed store, hash-verified

623 If there are free sequence blocks (seq->free_blocks != 0)
624 they are reused, otherwise the space is allocated in the storage: */
625static void
626icvGrowSeq( CvSeq *seq, int in_front_of )
627{
628 CvSeqBlock *block;
629
630 if( !seq )
631 CV_Error( CV_StsNullPtr, "" );
632 block = seq->free_blocks;
633
634 if( !block )
635 {
636 int elem_size = seq->elem_size;
637 int delta_elems = seq->delta_elems;
638 CvMemStorage *storage = seq->storage;
639
640 if( seq->total >= delta_elems*4 )
641 cvSetSeqBlockSize( seq, delta_elems*2 );
642
643 if( !storage )
644 CV_Error( CV_StsNullPtr, "The sequence has NULL storage pointer" );
645
646 /* If there is a free space just after last allocated block
647 and it is big enough then enlarge the last block.
648 This can happen only if the new block is added to the end of sequence: */
649 if( (size_t)(ICV_FREE_PTR(storage) - seq->block_max) < CV_STRUCT_ALIGN &&
650 storage->free_space >= seq->elem_size && !in_front_of )
651 {
652 int delta = storage->free_space / elem_size;
653
654 delta = MIN( delta, delta_elems ) * elem_size;
655 seq->block_max += delta;
656 storage->free_space = cvAlignLeft((int)(((schar*)storage->top + storage->block_size) -
657 seq->block_max), CV_STRUCT_ALIGN );
658 return;
659 }
660 else
661 {
662 int delta = elem_size * delta_elems + ICV_ALIGNED_SEQ_BLOCK_SIZE;
663
664 /* Try to allocate <delta_elements> elements: */
665 if( storage->free_space < delta )
666 {
667 int small_block_size = MAX(1, delta_elems/3)*elem_size +
668 ICV_ALIGNED_SEQ_BLOCK_SIZE;
669 /* try to allocate smaller part */
670 if( storage->free_space >= small_block_size + CV_STRUCT_ALIGN )
671 {
672 delta = (storage->free_space - ICV_ALIGNED_SEQ_BLOCK_SIZE)/seq->elem_size;
673 delta = delta*seq->elem_size + ICV_ALIGNED_SEQ_BLOCK_SIZE;
674 }
675 else
676 {
677 icvGoNextMemBlock( storage );
678 assert( storage->free_space >= delta );
679 }
680 }
681
682 block = (CvSeqBlock*)cvMemStorageAlloc( storage, delta );

Callers 6

cvCreateSeqBlockFunction · 0.85
cvSeqPushFunction · 0.85
cvSeqPushFrontFunction · 0.85
cvSeqInsertFunction · 0.85
cvSeqPushMultiFunction · 0.85
cvSetAddFunction · 0.85

Calls 5

cvSetSeqBlockSizeFunction · 0.85
cvAlignLeftFunction · 0.85
icvGoNextMemBlockFunction · 0.85
cvMemStorageAllocFunction · 0.85
cvAlignPtrFunction · 0.85

Tested by

no test coverage detected