小编kis*_*tic的帖子

pthread_create()和内存泄漏

这个问题似乎被问了很多.我有一些看似很好的遗留生产代码,直到它每天开始获得更多连接.每个连接都启动了一个新线程.最终,它会耗尽内存和崩溃.

我要回到pthread(和C套接字),多年来我没有处理过.我的教程内容丰富,但是当我使用top时,我看到同样的事情.所有线程退出,但仍有一些虚拟内存占用.Valgrind告诉我调用pthread_create()时可能会丢失内存.最基本的示例代码如下.

最可怕的部分是,当所有线程退出时,pthread_exit(NULL)似乎在VIRT中留下大约100米的未命中.如果我注释掉这条线,那就更适合居住了,但还是有一些.在我的系统上,它以大约14k开始,以47k结束.

如果我把线程计数提高到10,000,VIRT会上升到70+演出,但是大约在50k左右完成,假设我注释掉了pthread_exit(NULL).如果我使用pthread_exit(NULL),它仍然在VIRT中完成大约113m.这些可以接受吗?顶级不告诉我一切吗?

void* run_thread( void* id )
{
    int thread_id = *(int*)id;
    int count = 0;
    while ( count < 10 ) {
        sleep( 1 );
        printf( "Thread %d at count %d\n", thread_id, count++ );
    }

    pthread_exit( NULL );
    return 0;
}

int main( int argc, char* argv[] )
{
    sleep( 5 ); 
    int thread_count    = 0;
    while( thread_count < 10 ) {
        pthread_t my_thread;
        if ( pthread_create( &my_thread, NULL, run_thread, (void*)&thread_count ) < 0 )   {
            perror( …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading memory-leaks pthreads

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

Qt5信号/插槽语法带有过载信号和lambda

我正在使用信号/插槽连接的新语法.它对我来说很好,除非我尝试连接一个超载的信号.

MyClass : public QWidget
{
    Q_OBJECT
public:
    void setup()
    {
        QComboBox* myBox = new QComboBox( this );
        // add stuff
        connect( myBox, &QComboBox::currentIndexChanged, [=]( int ix ) { emit( changedIndex( ix ) ); } ); // no dice
        connect( myBox, &QComboBox::editTextChanged, [=]( const QString& str ) { emit( textChanged( str ) ); } ); // this compiles
    }
private:

signals:
    void changedIndex( int );
    void textChanged( const QString& );
};
Run Code Online (Sandbox Code Playgroud)

不同的是currentIndexChanged被重载(int和const QString&types)但editTextChanged不是.非过载信号连接良好.超载的没有.我想我错过了什么?使用GCC 4.9.1,我得到的错误是

no matching function for call to …
Run Code Online (Sandbox Code Playgroud)

c++ lambda qt5

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

在Linux上使用C++对Active Directory进行身份验证

我很惊讶那里的例子很少.我基本上需要针对Active Directory进行用户/通过身份验证.我能够初始化到活动目录的连接,但它总是给我一个"无效的凭据"错误.我想知道我是不是错了.这是我第一次使用LDAP.就此而言,我对另一个(也许有很多文件记录)解决方案持开放态度.

#include <iostream>
#include <stdio.h>

#define LDAP_SERVER "ldap://hq.mydomain.local/"

#include <ldap.h>

int main( int argc, char** argv )
{
    LDAP    *ld;
    int     version( LDAP_VERSION3 );
    int     rc;
    char    bind_dn[100];
    berval  creds;
    berval* serverCreds;

    if( ldap_initialize( &ld, LDAP_SERVER ) ) {
        std::cerr << "Error initializing ldap..." << std::endl;
        return 1;
    }

    ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );

    creds.bv_val = "password";
    creds.bv_len = strlen("password");

    rc = ldap_sasl_bind_s( ld, "sAMAccountName=MYDOMAIN\\UserName,dc=mydomain,dc=local", "GSSAPI", &creds, NULL, NULL, &serverCreds );

    if ( rc != LDAP_SUCCESS ) {
        std::cerr …
Run Code Online (Sandbox Code Playgroud)

c++ linux kerberos active-directory

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

AngularModalService:将数据传递给控制器

没有太多的搜索.我在这里找到了一个类似的线程,但它对我来说并不适用.

这些示例表明Modal将获得一个单独的控制器.看起来像这样.

var app = angular.module('myApp', ['ngSanitize','angularModalService']);
app.controller('SampleController', ['$scope', function($scope) {

    $scope.showAlert = function() {

        ModalService.showModal({
            templateUrl: "alertWindow.html",
            controller: "AlertController",
            inputs: {
                title: "Add New Alert",
            }
        }).then(function(modal) {
            modal.element.modal();
            modal.close.then(function(result) {
                $scope.result = "blah";
            });
        });

     });
}]);

app.controller('AlertController', ['$scope', function($scope) {

    $scope.close = function(result) {
        close(result, 500); 
    };
}]);
Run Code Online (Sandbox Code Playgroud)

我需要注意的是,我希望模态对话框具有SampleController中的一些默认值.我读了服务,但我认为这不起作用.输入:showModal()中的{}看起来很可疑,但是一旦显示模态窗口,我就不确定从哪里获取它.我见过的其他例子只显示简单的是/否按钮或文本输入w /空默认值.

modal-dialog angularjs angular-ui-bootstrap

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

Twig调试(我没有config.yml)

很久以后我又回到了PHP游戏中.我正在看Twig,需要了解更多正在发生的事情.我发现了一些需要进入config.yml文件的文本.警告:它不在我的系统上.它是否来自Twig版本或我是否也必须安装Symfony?有点迷失在这里.

干杯.

编辑:我只需要{{dump(var)}}来工作.httpd错误日志告诉我:PHP致命错误:未捕获异常'Twig_Error_Syntax',消息'the function"dump"不存在于

我正在设置我的Twig环境:

$twig = new Twig_Environment( $loader, array(
    'cache' => '/tmp',
    'debug' => true
));
Run Code Online (Sandbox Code Playgroud)

php debugging twig

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

AngularJS angular-modal-service给我一个错误

我正在尝试(不成功)使用AngularModalService.从公认的简单教程中执行复制/粘贴作业会给我一个错误.

这是教程,供参考:http: //www.dwmkerr.com/the-only-angularjs-modal-service-youll-ever-need/

使用Javascript:

var app = angular.module('app', ['angularModalService']);

app.controller( 'Controller', function($scope,ModalService) {

    $scope.show = function() {
        ModalService.showModal({
            templateUrl: 'modal.html',
            controller: "ModalController"
        }).then(function(modal) {
            modal.element.modal(); // this is the problem
            modal.close.then(function(result) {
                $scope.message = "You said " + result;
            });
        });
    };
});

app.controller('ModalController', function( $scope, close ) {
    $scope.close = function(result) {
        close(result, 500);
    };
});

</script>
Run Code Online (Sandbox Code Playgroud)

HTML(教程中的丑陋,但应该更简单)

<div class="container" style="min-width: 700px; max-width: 700px; margin: 50px auto;" data-ng-app="app" data-ng-controller="Controller">
    <h3>Angular Modal Service</h3>
    <a class="btn btn-default" href ng-click="show()">Show …
Run Code Online (Sandbox Code Playgroud)

javascript modal-dialog angularjs

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

NodeJS捕获错误的最佳实践

我开始用NodeJS和Express.来自其他流行的脚本语言和C++背景,异步调用数据库函数有点陌生.我已经整理出一个模式,但我仍然对捕获异常感到好奇.以下是我的基本模式.

var callback = function(req, res) {
    // do stuff
    connection.query(queryString, function(err,result){
        if (err) throw err;
        // process results.
    };
};

var express = require('express');
var app     = express();

app.get('/', callback);
app.listen(3000,function() {
    console.log('listening');
};
Run Code Online (Sandbox Code Playgroud)

通常我有很多端点和回调.我在设置ta try/catch块的地方有点迷失,以捕获回调中抛出的错误.我四处寻找一些建议,但其中很多似乎都在使用Web框架(如果有的话).

error-handling node.js express

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