我想分析核心文件分析中的内存泄漏.
我编写了示例代码来注入内存泄漏并使用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) AWS最近启动了类似于MongoDB接口的新服务DocumentDB。
AWS DynamoDB服务与DocumentDB服务之间有什么区别?
用法:在我们的生产中,我们有大约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存在性能问题:
问题
boost::shared_mutex在读取的情况下是否会影响性能?g++4.4?reads are lock free?此外,我们还打算用来Map保存缓存信息.
在C++ 11 中使用value([=])或reference([&])使用lambda默认捕获有什么缺陷?
我知道一些陷阱,如:
按值划分的默认值是否有任何缺点?
功能模板与转发参考参数之间有什么区别
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
更新
我已经通过链接(例如何时使用大括号括起来的初始化程序?)何时应该使用{}大括号初始化,但是当我们应该使用括号( )与初始化{ }语法来初始化C++中的对象时,没有给出信息./ 14?什么标准的做法,建议使用()过{}?
在极少数情况下,例如vector<int> v(10,20);或auto v = vector<int>(10,20);,结果是std::vector10个元素.如果我们使用大括号,结果是std::vector2个元素.但这取决于调用者的用例:要么他/她想要分配10个元素的矢量还是2个元素?
我可以在 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) 为什么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是右值参考?
最基本的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) c++ ×6
c++11 ×2
c++14 ×2
auto ×1
boost-thread ×1
c ×1
c++98 ×1
constructor ×1
coredump ×1
docker ×1
dockerfile ×1
gcore ×1
go ×1
lambda ×1
template-argument-deduction ×1
templates ×1
vector ×1