小编Aja*_*dav的帖子

如何分析coredump的内存泄漏

我想分析核心文件分析中的内存泄漏.

我编写了示例代码来注入内存泄漏并使用gcore命令生成核心文件.

#include <stdlib.h>
#include <unistd.h>
void fun()
{
  int *ptr = new int(1234);
}
int main()
{
  int i=0;
  while(i++<2500)
  {
    fun();
}
sleep(360);
return 0;
}
Run Code Online (Sandbox Code Playgroud)

找到进程ID

ayadav@ajay-PC:~$ ps -aef |grep over  
ajay      8735  6016  0 12:57 pts/2    00:00:00 ./over  
ayadav    8739  4659  0 12:57 pts/10   00:00:00 grep over  
Run Code Online (Sandbox Code Playgroud)

并生成核心

ayadav@ajay-PC:~$ sudo gcore 8735
[sudo] password for ayadav:
0x00007fbb7dda99a0 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:81
81      ../sysdeps/unix/syscall-template.S: No such file or directory.
Saved corefile core.8735
Run Code Online (Sandbox Code Playgroud)

我已经从核心文件中找到了常见的模式,如下所示(在stackoverflow上建议另一个线程有没有办法找到进程的哪个部分使用了大部分内存,只查看生成的核心文件?)

ayadav@ajay-PC:~$ …
Run Code Online (Sandbox Code Playgroud)

c coredump gcore

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

AWS DynamoDB与AWS DocumentDB(新推出的服务)之间的区别?

AWS最近启动了类似于MongoDB接口的新服务DocumentDB。
AWS DynamoDB服务与DocumentDB服务之间有什么区别?

amazon-web-services amazon-dynamodb aws-documentdb-mongoapi

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

通过boost :: shared_mutex对g ++ - 4.4(不是C++ 11/14)中的多个读者单一编写器实现会影响性能吗?

用法:在我们的生产中,我们有大约100个线程,可以访问我们试图实现的缓存.如果错过了缓存,则将从数据库中获取信息,并且将通过编写器线程更新缓存.

为此,我们计划实现multiple read and single writer我们无法更新g ++版本,因为我们正在使用g++-4.4

更新:每个工作线程都可以用于读取和写入.如果错过了缓存,则从DB缓存信息.

问题陈述: 我们需要实现缓存以提高性能.为此,缓存读取更频繁,对缓存的写入操作非常少.

我觉得可以用boost::shared_mutex boost::shared_lock,boost::upgrade_lock,boost::upgrade_to_unique_lock implementation

但我们了解到boost::shared_mutex存在性能问题:

问题

  1. boost::shared_mutex在读取的情况下是否会影响性能?
  2. 在考虑编译器版本时,我们可以采取哪些其他构造和设计方法g++4.4?
  3. 有没有解决方法如何设计呢reads are lock free?

此外,我们还打算用来Map保存缓存信息.

c++ multithreading multiprocessing boost-thread

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

在C++ 11中使用lambda默认捕获值或引用的缺点?

在C++ 11 中使用value([=])或reference([&])使用lambda默认捕获有什么缺陷?

我知道一些陷阱,如:

  • 如果从lambda创建的闭包的生命周期超过了局部变量的生命周期,那么闭包中的引用将是悬空的?

按值划分的默认值是否有任何缺点?

c++ lambda

8
推荐指数
3
解决办法
1907
查看次数

缩写功能模板与具有转发参考参数的功能模板

功能模板与转发参考参数之间有什么区别

template<typename T>
void Universal_func(T && a)
{
}
Run Code Online (Sandbox Code Playgroud)

和缩写功能模板?

void auto_fun(auto && a)
{
}
Run Code Online (Sandbox Code Playgroud)

我可以代替Universal_func用auto_fun?是Universal_func一个的auto_fun或者是他们平等的吗?

我测试了下面的程序.似乎两者都是一样的.

template<typename T>
void Universal_func(T && a)
{
}

void auto_fun(auto && a)
{
}

int main()
{
  int i;   
  const int const_i = 0; 
  const int const_ref =const_i; 
  //forwarding reference template function example  
  Universal_func(1); //call void Universal_func<int>(int&&)
  Universal_func(i);//call void Universal_func<int&>(int&):
  Universal_func(const_i); //call void Universal_func<int const&>(int const&)
  Universal_func(const_ref);//call void Universal_func<int const&>(int const&) …
Run Code Online (Sandbox Code Playgroud)

c++ templates type-deduction template-argument-deduction c++14

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

我们什么时候应该使用括号()与初始化{}语法来初始化C++ 11中的对象?

更新

我已经通过链接(例如何时使用大括号括起来的初始化程序?)何时应该使用{}大括号初始化,但是当我们应该使用括号( )与初始化{ }语法来初始化C++中的对象时,没有给出信息./ 14?什么标准的做法,建议使用()过{}?

在极少数情况下,例如vector<int> v(10,20);或auto v = vector<int>(10,20);,结果是std::vector10个元素.如果我们使用大括号,结果是std::vector2个元素.但这取决于调用者的用例:要么他/她想要分配10个元素的矢量还是2个元素?

c++ initialization c++11 c++14

8
推荐指数
2
解决办法
2806
查看次数

在 C++98 中实现移动构造函数和移动赋值运算符以获得更好的性能

我可以在 C++98 中使用复制构造函数和赋值运算符模拟移动构造函数和移动赋值运算符的功能,以提高性能,只要我知道复制构造函数和复制赋值将只为代码中的临时对象调用,或者我在我的代码中插入针吗?眼睛?

我举了两个例子,一个是普通的复制构造函数和复制赋值运算符,另一个是模拟移动构造函数和移动赋值运算符,并在向量中推送 10000 个元素来调用复制构造函数。

普通复制构造函数和复制赋值运算符的示例(copy.cpp)

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

class MemoryBlock
{
public:

   // Simple constructor that initializes the resource.
   explicit MemoryBlock(int length)
      : _length(length)
      , _data(new int[length])
   {
   }

   // Destructor.
   ~MemoryBlock()
   {

      if (_data != NULL)
      {
         // Delete the resource.
         delete[] _data;
      }
   }


//copy constructor.
MemoryBlock(const MemoryBlock& other): _length(other._length)
      , _data(new int[other._length])
{

      std::copy(other._data, other._data + _length, _data);
}

// copy assignment operator.
MemoryBlock& operator=(MemoryBlock& other)
{
  //implementation of …
Run Code Online (Sandbox Code Playgroud)

c++ constructor vector copy-constructor c++98

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

auto && variable不是右值引用

为什么auto &&不是右值参考?

Widget&& var1 = Widget(); // rvalue reference
auto&& var2 = var1; //var2 not rvalue reference
Run Code Online (Sandbox Code Playgroud)

下面是右值参考示例

void f(Widget&& param); // rvalue reference
Widget&& var1 = Widget(); // rvalue reference
Run Code Online (Sandbox Code Playgroud)

为什么var2不是右值参考,而f和var2是右值参考?

c++ auto c++11 forwarding-reference

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

standard_init_linux.go:190:exec用户进程导致"没有这样的文件或目录"Docker与go基本web应用程序

最基本的Web应用程序是在Go中创建的

package main

import(
   "fmt"
   "net/http"
   "os"
)

func hostHandler(w http.ResponseWriter, r *http.Request){
    name, err :=os.Hostname()

    if err != nil {
           panic(err)
        }

        fmt.Fprintf(w, "<h1>HOSTNAME: %s</h1><br>",name)
        fmt.Fprintf(w, "<h1>ENVIRONMENT VARS: </h1><br>")
        fmt.Fprintf(w, "<ul>")

        for _, evar := range os.Environ(){
            fmt.Fprintf(w, "<li>%s</li>",evar)
        }
        fmt.Fprintf(w, "</ul>")

}

func rootHandler(w http.ResponseWriter, r *http.Request){

    fmt.Fprintf(w, "<h1>Awesome site in Go!</h1><br>")
    fmt.Fprintf(w, "<a href='/host/'>Host info</a><br>")

}

func main() {

        http.HandleFunc("/", rootHandler)
        http.HandleFunc("/host/", hostHandler)
        http.ListenAndServe(":8080", nil)


}
Run Code Online (Sandbox Code Playgroud)

它的Docker文件

FROM scratch
WORKDIR /home/ubuntu/go
COPY webapp /
EXPOSE 8080
CMD …
Run Code Online (Sandbox Code Playgroud)

go docker dockerfile

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