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

1.2       paf         1: /** @file
                      2:        Parser: memory reference counting classes.
                      3: 
1.14    ! moko        4:        Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com)
1.2       paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
                      6: */
                      7: 
                      8: #include "pa_sapi.h"
                      9: #include "pa_common.h"
                     10: 
1.14    ! moko       11: volatile const char * IDENT_PA_MEMORY_C="$Id: pa_memory.C,v 1.13 2016/09/21 12:03:40 moko Exp $" IDENT_PA_MEMORY_H;
1.13      moko       12: 
                     13: //{@ Array-oriented
                     14: void *operator new[] (size_t size, bool) { // PointerFreeGC
                     15:        return pa_malloc_atomic(size);
                     16: }
                     17: void *operator new[] (std::size_t size) PA_THROW(std::bad_alloc) {
                     18:        return pa_malloc(size);
                     19: }
                     20: void operator delete[] (void *ptr) throw() {
                     21:        pa_free(ptr);
                     22: }
                     23: //}@
                     24: 
                     25: //{@ Structure-oriented
                     26: void *operator new (size_t size, bool) { // PointerFreeGC
                     27:        return pa_malloc_atomic(size);
                     28: }
                     29: void *operator new(std::size_t size) PA_THROW(std::bad_alloc) {
                     30:        return pa_malloc(size);
                     31: }
                     32: void operator delete(void *ptr) throw() {
                     33:        pa_free(ptr);
                     34: }
                     35: //}@
                     36: 
1.9       moko       37: 
1.2       paf        38: void *pa_fail_alloc(const char* what, size_t size) {
                     39: #ifdef PA_DEBUG_DISABLE_GC
                     40:        SAPI::die("out of memory (in pa_fail_alloc)");
                     41: #else
1.12      moko       42:        SAPI::die("out of memory: failed to %s %u bytes. heap_used=%u, heap_free=%u, bytes_since_gc=%u, total_bytes=%u",
                     43:                what, size, GC_get_heap_size(), GC_get_free_bytes(), GC_get_bytes_since_gc(), GC_get_total_bytes());
1.2       paf        44: #endif
                     45:        // never reached
                     46:        return 0;
                     47: }
1.12      moko       48: 
                     49: #ifdef _MSC_VER
                     50: extern "C" void *pa_fail_alloc(const char* what);
                     51: void *pa_fail_alloc(const char* what) {
                     52:        SAPI::die("fatal memory error: %s. heap_used=%u, heap_free=%u, bytes_since_gc=%u, total_bytes=%u",
                     53:                what, GC_get_heap_size(), GC_get_free_bytes(), GC_get_bytes_since_gc(), GC_get_total_bytes());
                     54:        // never reached
                     55:        return 0;
                     56: }
                     57: #endif

E-mail: