- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 VC express 2008 下使用 Loki::Singleton、Loki::SmartPtr 和 std::vector 时遇到了问题. 以下是我的来源。
#include <iostream>
#include <vector>
#include <loki/Singleton.h>
#include <loki/SmartPtr.h>
class Foo {
public:
std::vector<Loki::SmartPtr<Foo>> children ;
void add() {
Loki::SmartPtr<Foo> f = new Foo ;
children.push_back(f) ;
}
Foo () {
}
~Foo () {
}
} ;
typedef Loki::SingletonHolder<Foo> SingletonFoo ;
int main ()
{
std::cout << "Start" << std::endl ;
SingletonFoo::Instance().add() ;
std::cout << "End" << std::endl ;
}
编译和链接没有问题,但是程序执行完后,报错:
Windows has triggered a breakpoint in test.exe.
This may be due to a corruption of the heap, which indicates a bug in test.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while test.exe has focus.
The output window may have more diagnostic information.
似乎有些内存被删除了两次,我不太确定。这是 VC 的错误还是我想念用过的 Loki?
提前致谢。
最佳答案
当您使用 VC 时,您应该能够在 Debug模式下运行您的代码,按 stp (F10,F11) 逐步查看它在哪里中断。
无论如何,看着Loki singleton code ,似乎错误来自 SingletonHolder::DestroySingleton() 中的断言:
SingletonHolder<T, CreationPolicy, L, M, X>::DestroySingleton()
00837 {
00838 assert(!destroyed_); // there, but it's a wild guess
00839 CreationPolicy<T>::Destroy(pInstance_);
00840 pInstance_ = 0;
00841 destroyed_ = true;
00842 }
该函数似乎由 LifetimePolicy(此处为 DefaultLifetime)调用,正如这段代码所暗示的那样:
00800 template
00801 <
00802 class T,
00803 template <class> class CreationPolicy,
00804 template <class> class LifetimePolicy,
00805 template <class, class> class ThreadingModel,
00806 class MutexPolicy
00807 >
00808 void SingletonHolder<T, CreationPolicy,
00809 LifetimePolicy, ThreadingModel, MutexPolicy>::MakeInstance()
00810 {
00811 typename ThreadingModel<SingletonHolder,MutexPolicy>::Lock guard;
00812 (void)guard;
00813
00814 if (!pInstance_)
00815 {
00816 if (destroyed_)
00817 {
00818 destroyed_ = false;
00819 LifetimePolicy<T>::OnDeadReference();
00820 }
00821 pInstance_ = CreationPolicy<T>::Create();
00822 LifetimePolicy<T>::ScheduleDestruction(pInstance_, // here
00823 &DestroySingleton);
00824 }
00825 }
我不确定为什么它被调用两次,但我猜指向单例的指针首先在 SingletonHolder 实例销毁时被销毁(指针,而不是实例),然后 LifetimePolicy 尝试调用它的 DestroySingleton() 函数...
但我可能错了,你必须检查一下。
关于c++ - Loki::Singleton、Loki::SmartPtr 和std::vector 奇怪的内存问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1094276/
我正在尝试将我的日志从 .netcore 3.1 API 发送到 Loki 服务器。为此,我正在使用 Serilog-Sinks-Loki 金块包。 当我运行我的代码时,日志会立即发送,我可以在 Gr
我在 VC express 2008 下使用 Loki::Singleton、Loki::SmartPtr 和 std::vector 时遇到了问题. 以下是我的来源。 #include #incl
前面我们介绍了 Loki 的一些基本使用配置,但是对 Loki 还是了解不够深入,官方文档写得较为凌乱,而且没有跟上新版本,为了能够对 Loki 有一个更深入的认识,做到有的放矢,这
我正在研究loki源代码。下面是MakeTypelist,这让我感到困惑。 class NullType {}; template struct Typelist { typedef T H
我使用官方 helm 图表在 EKS 中运行 loki + grafana + prometheus。 我想根据错误日志消息发送警报,为此我正在尝试使用 loki 标尺。 以下是标尺配置 ruler:
我正在尝试配置录制规则,根据文档,目前还不清楚如何设置。 我在 /loki/rules 中配置了 rules.yml 文件目录。根据文档 Recording rules ,我执行我自己的规则: nam
我正在 Grafana 上开发基于 Loki 的仪表板。我有一个用于在 Loki 跟踪日志中搜索文本的面板,当前查询如下: {job="abc-service"} |~ "searchTrace" |
我是 Loki 的新手,在 Loki 中发出了警报,但我在 Alertmanager 中没有看到任何通知。 Loki 工作正常(收集日志),Alertmanager 也正常(从其他来源获取警报),但来
我正在使用 Grafana Loki,我需要计算特定时间间隔内特定日志消息的总数。例如,我需要从 12:00:00 到 14:00:00 期间的日志消息“some-text”的总数。我刚刚找到了以下方
我的集群中有一个 grafana Loki 日志。我可以看到我的日志,但目前该集群已不再使用,我想删除它,但我仍然有一些日志,我想提取 Loki 并可能将其存储在我的系统本地或 Azure 上桶。 有
我已经使用 grafana/loki-stack 安装了 Grafana、Loki、Promtail 和 Prometheus . 我还使用 Nginx helm chart 设置了 Nginx .
[更新]我后来发现了一些例子,如下: this.db = new Loki("viewsaving", { autosave: true,
有没有办法在 loki 中指定复合唯一索引?我尝试过类似的方法: db.addCollection('contents', {unique: ['id', 'wsID']}); 但这似乎产生了 2 个
我的集群中有一个 grafana Loki 日志。我可以看到我的日志,但目前该集群已不再使用,我想删除它,但我仍然有一些日志,我想提取 Loki 并可能将其存储在我的系统本地或 Azure 上桶。 有
我在项目中使用 Loki::Functor 来构建简单的事件系统。该事件的处理函数带有一些参数。在本例中,它称为 PrintEventString。为了将其放入队列中,事件处理程序必须具有相同的原型(
我已经使用 grafana/loki-stack 安装了 Grafana、Loki、Promtail 和 Prometheus . 我还使用 Nginx helm chart 设置了 Nginx .
我正在尝试在使用 VC8 编译的项目中使用 Loki::Factory(我不允许切换到更新的编译器)。当程序退出时我遇到了一个问题,我可以用这个基本代码重现这个问题(这是你在使用工厂时可能想要实现的最
我正在尝试在浏览器应用中使用 loki.js。我在 HTML 中包含了以下脚本 但是下面的js代码给了我“unexpected token”错误 db = new loki('test'); 最佳答
我需要使用 Loki 的小对象分配器,但我对它的工作原理感到非常困惑。我已经阅读了文档和许多论坛,但它没有意义:其中一些说使用 STL,其他人使用自定义分配器。我只需要能够通过分配和取消分配不同大小的
Loki库实现了一些非常广泛使用的概念(智能指针、访问者、工厂等)。相关书籍《Modern C++ Design》经常被提及,但库本身并没有被广泛使用。这是为什么呢? 大多数开发人员似乎更喜欢 Boo
我是一名优秀的程序员,十分优秀!