Ignore:
Timestamp:
Oct 18, 2021, 4:31:04 PM (3 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
6f7aff3
Parents:
804bf677
Message:

String heap growth implemented

Location:
libcfa/src/containers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/containers/string_res.cfa

    r804bf677 r7b0e8b7  
    4444   
    4545static inline void compaction( VbyteHeap & );                           // compaction of the byte area
    46 static inline void garbage( VbyteHeap & );                              // garbage collect the byte area
     46static inline void garbage( VbyteHeap &, int );                         // garbage collect the byte area
    4747static inline void extend( VbyteHeap &, int );                  // extend the size of the byte area
    4848static inline void reduce( VbyteHeap &, int );                  // reduce the size of the byte area
     
    179179}
    180180
     181size_t DEBUG_string_bytes_in_heap( VbyteHeap * heap ) {
     182    return heap->CurrSize;
     183}
     184
    181185const char * DEBUG_string_heap_start( VbyteHeap * heap ) {
    182186    return heap->StartVbyte;
    183187}
    184 
    185188
    186189// Returns the size of the string in bytes
     
    759762    NoBytes = ( uintptr_t )EndVbyte + size;
    760763    if ( NoBytes > ( uintptr_t )ExtVbyte ) {            // enough room for new byte-string ?
    761                 garbage( this );                                        // firer up the garbage collector
     764                garbage( this, size );                                  // firer up the garbage collector
    762765                NoBytes = ( uintptr_t )EndVbyte + size;         // try again
    763766                if ( NoBytes > ( uintptr_t )ExtVbyte ) {        // enough room for new byte-string ?
    764 // unimplemented feature - assert, not verify
    765 assert( 0 && "need to implement actual growth" );
    766                         // extend( size );                              // extend the byte-string area
     767            assert( 0 && "garbage run did not free up required space" );
    767768                } // if
    768769    } // if
     
    925926// the heap.  The heap is then compacted in the existing heap or into the newly allocated heap.
    926927
    927 void garbage(VbyteHeap & this ) with(this) {
     928void garbage(VbyteHeap & this, int minreq ) with(this) {
    928929#ifdef VbyteDebug
    929930    serr | "enter:garbage";
     
    949950    AmountFree = ( uintptr_t )ExtVbyte - ( uintptr_t )StartVbyte - AmountUsed;
    950951   
    951     if ( AmountFree < ( int )( CurrSize * 0.1 )) {      // free space less than 10% ?
    952 
    953 // unimplemented feature - assert, not verify
    954 assert( 0 && "need to implement actual growth" );
    955 //              extend( CurrSize );                             // extend the heap
     952    if ( ( double ) AmountFree < ( CurrSize * 0.1 ) || AmountFree < minreq ) {  // free space less than 10%  or not enough to serve cur request
     953
     954                extend( this, max( CurrSize, minreq ) );                                // extend the heap
    956955
    957956                        //  Peter says, "This needs work before it should be used."
     
    980979#undef VbyteDebug
    981980
    982 //WIP
    983 #if 0
    984981
    985982
     
    987984// area is deleted.
    988985
    989 void VbyteHeap::extend( int size ) {
     986void extend( VbyteHeap & this, int size ) with (this) {
    990987#ifdef VbyteDebug
    991988    serr | "enter:extend, size:" | size;
     
    997994   
    998995    CurrSize += size > InitSize ? size : InitSize;      // minimum extension, initial size
    999     StartVbyte = EndVbyte = new char[CurrSize];
     996    StartVbyte = EndVbyte = alloc(CurrSize);
    1000997    ExtVbyte = (void *)( StartVbyte + CurrSize );
    1001     compaction();                                       // copy from old heap to new & adjust pointers to new heap
    1002     delete OldStartVbyte;                               // release old heap
     998    compaction(this);                                   // copy from old heap to new & adjust pointers to new heap
     999    free( OldStartVbyte );                              // release old heap
    10031000#ifdef VbyteDebug
    10041001    serr | "exit:extend, CurrSize:" | CurrSize;
     
    10061003} // extend
    10071004
     1005//WIP
     1006#if 0
    10081007
    10091008// Extend the size of the byte-string area by creating a new area and copying the old area into it. The old byte-string
  • libcfa/src/containers/string_res.hfa

    r804bf677 r7b0e8b7  
    3434
    3535VbyteHeap * DEBUG_string_heap();
     36size_t DEBUG_string_bytes_in_heap( VbyteHeap * heap );
    3637size_t DEBUG_string_bytes_avail_until_gc( VbyteHeap * heap );
    3738const char * DEBUG_string_heap_start( VbyteHeap * heap );
Note: See TracChangeset for help on using the changeset viewer.