首页 > 关于STL的alloc

关于STL的alloc

    template<int inst>
    void (*__malloc_alloc_template<inst>::set_malloc_handler(void(*f)()))()
    {
        void(*old)() = __malloc_alloc_oom_handler;
        __malloc_alloc_oom_handler = f;
        return (old);
    }

为什么是返回old?而不是返回__malloc_alloc_oom_handler ?

void (*__malloc_alloc_template<inst>::__malloc_alloc_oom_handler)() = 0;

在这里把__malloc_alloc_oom_handler设置为了0,那么在上面那个函数old的值不也为0吗?那么我调用这个返回的old就会出错呀,为什么这么做呢?


返回old是返回上一个alloc_handler,

__malloc_alloc_oom_handler = f;
这里都已经设置老的hanlder为新的f了,你再返回它有意义吗,好比你传入了一个参数,结果你这个函数的返回值还是还是这个参数,没有任何意义的。
【热门文章】
【热门文章】