长字符串在 Release 模式下调用字符串的析构函数

问题描述

我刚刚遇到一个奇怪的错误代码在调试模式下工作,但在发布模式下不起作用。经过惨痛的调试,发现调用了如下函数(来源:xstring),程序跳转到了if块_Mypair._Myval2._Large_string_engaged()。然后,我相信一些重要的对象被破坏了,整个程序崩溃了。当我更改长字符串的长度时,错误消失。我想知道为什么会发生这种情况,以及如何在 Release 模式下使用长字符串。字符串大约有 20 个字母。

    void _Tidy_deallocate() noexcept { // initialize buffer,deallocating any storage
        _Mypair._Myval2._Orphan_all();
        if (_Mypair._Myval2._Large_string_engaged()) {
            const pointer _Ptr = _Mypair._Myval2._Bx._Ptr;
            auto& _Al          = _Getal();
            _Destroy_in_place(_Mypair._Myval2._Bx._Ptr);
            _Al.deallocate(_Ptr,_Mypair._Myval2._Myres + 1);
        }

        _Mypair._Myval2._Mysize = 0;
        _Mypair._Myval2._Myres  = _BUF_SIZE - 1;
        // the _Traits::assign is last so the codegen doesn't think the char write can alias this
        _Traits::assign(_Mypair._Myval2._Bx._Buf[0],_Elem());
    }    void _Tidy_deallocate() noexcept { // initialize buffer,_Elem());
    }

程序在调试模式下运行良好,因为我认为调用了不同的内存函数

void __CRTDECL operator delete(void* const block) noexcept
{
    #ifdef _DEBUG
    _free_dbg(block,_UNKNowN_BLOCK);
    #else
    free(block);
    #endif
}

先谢谢你!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)