美文网首页
php garbage collect

php garbage collect

作者: littleDinosaur | 来源:发表于2018-02-08 13:31 被阅读0次

    按照之前的一样先把所有的宏列出来

    #define GC_G(v) ZEND_TSRMG(gc_globals_id, zend_gc_globals *, v)
    #else
    #define GC_G(v) (gc_globals.v)
    extern ZEND_API zend_gc_globals gc_globals;
    #endif
    

    然后看到初始化

    ZEND_API void gc_init(void)    // gc 初始化变量
    {
        if (GC_G(buf) == NULL && GC_G(gc_enabled)) {
            GC_G(buf) = (gc_root_buffer*) malloc(sizeof(gc_root_buffer) * GC_ROOT_BUFFER_MAX_ENTRIES);
            GC_G(last_unused) = &GC_G(buf)[GC_ROOT_BUFFER_MAX_ENTRIES];
            gc_reset();
        }
    }
    
    ZEND_API void gc_reset(void)
    {
    ...
    
        GC_G(roots).next = &GC_G(roots);   // root  自己引用自己
        GC_G(roots).prev = &GC_G(roots);   // root 自己引用自己
    
        GC_G(to_free).next = &GC_G(to_free);  // 和上面一样
        GC_G(to_free).prev = &GC_G(to_free);
    
        if (GC_G(buf)) {   
            GC_G(unused) = NULL;
            GC_G(first_unused) = GC_G(buf) + 1;
        } else {
            GC_G(unused) = NULL;
            GC_G(first_unused) = NULL;
            GC_G(last_unused) = NULL;
        }
    
        GC_G(additional_buffer) = NULL;    // 也是一个环型双向链表
    }
    

    相关文章

      网友评论

          本文标题:php garbage collect

          本文链接:https://www.haomeiwen.com/subject/jtkttftx.html