相关疑难解决方法(0)

创建2000个对象后,C++程序崩溃

我有一个程序,它创建了大量的对象并将它们插入到一个向量中.我的想法是创建大约10,000个对象,但我发现该程序在几千个之后崩溃了.在崩溃之前创建的对象数量是随机的,取决于我是否修改了代码中的任何行,所以我认为是一个与内存分配有关的问题.

我正在创建的对象是这样的:

class Object {
public:

    //Needed by map
    Object() {

    }

    Object(int newID, std::string newText) {
        id = newID;
        text = newText;
    }

    int getID() {
        return id;
    }

    std::string getText() {
        return text;
    }

    ~Object() {

    }

private:

    int id;
    std::string text;
};
Run Code Online (Sandbox Code Playgroud)

没有什么特别的,正如你所看到的.创建对象的程序如下:

int main(int argc, char** argv) {

int numberOfElements;
long start;
long end;
long time1, time2, time3, time4, time5, time6;


numberOfElements = 7000;  //7000<X<7050  Maximum reliable

{
    //Measuring time for creation of 1000 elements in …
Run Code Online (Sandbox Code Playgroud)

c++ memory-management vector object

3
推荐指数
2
解决办法
637
查看次数

像关系数据库一样使用boost多索引

这是我试图模拟的情况:

  COL1                 Col2     Col3
CBT.151.5.T.FEED       S1       t1
CBT.151.5.T.FEED       s2       t2
CBT.151.5.T.FEED       s3       t3
CBT.151.5.T.FEED       s4       t4
CBT.151.5.T.FEED       s5       t1

CBT.151.8.T.FEED       s7       t1
CBT.151.5.Q.FEED       s8       t3
Run Code Online (Sandbox Code Playgroud)

COL1 - 是ID,对于给定的ID,可以有多个符号.
COL2 - 符号,它们是唯一的
COL3 - 符号的更新时间,两个不同的符号可能同时更新,因此它们不是唯一的.

我的目标是获得最活跃的代码,让我们说出在过去60秒内更新过的符号.为此,我使用了boost multi索引.

头文件:

#ifndef __TICKER_INFO_MANAGER_IMPL__
#define __TICKER_INFO_MANAGER_IMPL__

#include <boost/interprocess/containers/string.hpp>
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <TickerInfoManagerConstants.h>
#include <TickerInfo.h>

namespace bmi = boost::multi_index;
namespace bip = boost::interprocess;

struct id_index{};
struct symbol_index{};
struct last_update_time_index{};

struct Less {
  template<class T, class U>
    bool operator()(T const& t, …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-multi-index

1
推荐指数
1
解决办法
691
查看次数