Ejemplo n.º 1
0
_WCRTLINK void _nfree( void _WCNEAR *stg )
{
    mheapptr            p1,p2;

    if( !stg )
        return;

    _AccessNHeap();
    do {
        // first try some likely locations
        p1 = __MiniHeapFreeRover;
        if( p1 ) {
            if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
                break;
            }
            p2 = p1;
            p1 = p1->prev;
            if( p1 ) {
                if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
                    break;
                }
            }
            p1 = p2->next;
            if( p1 ) {
                if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
                    break;
                }
            }
        }
        p1 = __MiniHeapRover;
        if( p1 ) {
            if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
                break;
            }
            p2 = p1;
            p1 = p1->prev;
            if( p1 ) {
                if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
                    break;
                }
            }
            p1 = p2->next;
            if( p1 ) {
                if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
                    break;
                }
            }
        }

        // not found near rover, so search the list
        for( p1 = __nheapbeg; p1; p1 = p1->next ) {
            if( (PTR)p1 <= (PTR)stg && (PTR)p1+p1->len > (PTR)stg ) {
                // break twice!
                goto found_it;
            }
        }

        // this pointer is not in the heap
        _ReleaseNHeap();
        return;
    } while( 0 );

found_it:
    // we found the miniheap, free the storage
    __MemFree( (unsigned)stg, _DGroup(), (unsigned) p1 );
    __MiniHeapFreeRover = p1;
    if( p1 < __MiniHeapRover ) {
        if( p1->largest_blk > __LargestSizeB4MiniHeapRover ) {
            __LargestSizeB4MiniHeapRover = p1->largest_blk;
        }
    }
    _ReleaseNHeap();
}
Ejemplo n.º 2
0
_WCRTLINK void _nfree( void_nptr cstg )
{
    heapblk_nptr    heap;
    heapblk_nptr    heap2;

    if( cstg == NULL )
        return;

    _AccessNHeap();
    do {
        // first try some likely locations
        heap = __MiniHeapFreeRover;
        if( heap != NULL ) {
            if( IS_IN_HEAP( cstg, heap ) ) {
                break;
            }
            heap2 = heap;
            heap = heap->prev.nptr;
            if( heap != NULL ) {
                if( IS_IN_HEAP( cstg, heap ) ) {
                    break;
                }
            }
            heap = heap2->next.nptr;
            if( heap != NULL ) {
                if( IS_IN_HEAP( cstg, heap ) ) {
                    break;
                }
            }
        }
        heap = __MiniHeapRover;
        if( heap != NULL ) {
            if( IS_IN_HEAP( cstg, heap ) ) {
                break;
            }
            heap2 = heap;
            heap = heap->prev.nptr;
            if( heap != NULL ) {
                if( IS_IN_HEAP( cstg, heap ) ) {
                    break;
                }
            }
            heap = heap2->next.nptr;
            if( heap != NULL ) {
                if( IS_IN_HEAP( cstg, heap ) ) {
                    break;
                }
            }
        }

        // not found near rover, so search the list
        for( heap = __nheapbeg; heap != NULL; heap = heap->next.nptr ) {
            if( IS_IN_HEAP( cstg, heap ) ) {
                // break twice!
                goto found_it;
            }
        }

        // this pointer is not in the heap
        _ReleaseNHeap();
        return;
    } while( 0 );

found_it:
    // we found the miniheap, free the storage
#ifdef _M_I86
    __MemFree( cstg, _DGroup(), heap );
#else
    __MemFree( cstg, heap );
#endif
    __MiniHeapFreeRover = heap;
    if( heap < __MiniHeapRover ) {
        if( __LargestSizeB4MiniHeapRover < heap->largest_blk ) {
            __LargestSizeB4MiniHeapRover = heap->largest_blk;
        }
    }
    _ReleaseNHeap();
}