Annotation of parser3/src/main/pa_memory.C, revision 1.22

1.2       paf         1: /** @file
                      2:        Parser: memory reference counting classes.
                      3: 
1.19      moko        4:        Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com)
1.18      moko        5:        Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.2       paf         6: */
                      7: 
                      8: #include "pa_sapi.h"
                      9: #include "pa_common.h"
1.17      moko       10: #include "pa_threads.h"
1.2       paf        11: 
1.22    ! moko       12: volatile const char * IDENT_PA_MEMORY_C="$Id: pa_memory.C,v 1.21 2024/11/09 17:26:39 moko Exp $" IDENT_PA_MEMORY_H;
1.9       moko       13: 
1.2       paf        14: void *pa_fail_alloc(const char* what, size_t size) {
                     15: #ifdef PA_DEBUG_DISABLE_GC
                     16:        SAPI::die("out of memory (in pa_fail_alloc)");
                     17: #else
1.12      moko       18:        SAPI::die("out of memory: failed to %s %u bytes. heap_used=%u, heap_free=%u, bytes_since_gc=%u, total_bytes=%u",
                     19:                what, size, GC_get_heap_size(), GC_get_free_bytes(), GC_get_bytes_since_gc(), GC_get_total_bytes());
1.2       paf        20: #endif
                     21:        // never reached
                     22:        return 0;
                     23: }
1.12      moko       24: 
1.21      moko       25: #ifdef _MSC_VER
1.22    ! moko       26: // pa_fail_alloc referenced in function GC_default_on_abort in gc.lib(misc.c) and thus should be extern "C"
        !            27: extern "C" void *pa_fail_alloc(const char* what);
        !            28: 
1.21      moko       29: void *pa_fail_alloc(const char* what) {
                     30:        SAPI::die("fatal memory error: %s. heap_used=%u, heap_free=%u, bytes_since_gc=%u, total_bytes=%u",
                     31:                what, GC_get_heap_size(), GC_get_free_bytes(), GC_get_bytes_since_gc(), GC_get_total_bytes());
                     32:        // never reached
                     33:        return 0;
                     34: }
                     35: #endif
                     36: 
1.17      moko       37: int pa_free_space_divisor = 0;
                     38: 
                     39: void pa_gc_collect(bool forced){
                     40: #ifndef PA_DEBUG_DISABLE_GC
                     41:     int divisor = pa_free_space_divisor; // as it can change during collect in multithreaded enviroment
                     42:     if(!divisor) GC_enable();
                     43:     if(!divisor || forced) GC_gcollect();
                     44:     if(!divisor) GC_disable();
                     45: #endif
                     46: }
                     47: 
                     48: void pa_gc_set_free_space_divisor(int divisor){
                     49: #ifndef PA_DEBUG_DISABLE_GC
                     50:        if(divisor != pa_free_space_divisor){
                     51:                SYNCHRONIZED;
                     52:                if(pa_free_space_divisor){
                     53:                        if(!divisor) GC_disable();
                     54:                } else {
                     55:                        if(divisor) GC_enable();
                     56:                }
                     57:                if(divisor)
                     58:                        GC_set_free_space_divisor(divisor);
                     59:                pa_free_space_divisor = divisor;
                     60:        }
                     61: #endif
                     62: }

E-mail: