小编pio*_*otr的帖子

用于提升python的指针参数

使用指针作为参数的函数使用boost python的最佳方法是什么?我看到文档中有很多返回值的可能性,但我不知道如何用参数来做.

void Tesuto::testp(std::string* s)
{
    if (!s)
        cout << " NULL s" << endl;
    else
        cout << s << endl;
}

>>> t.testp(None)
 NULL s
>>>       
>>> s='test'
>>> t.testp(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
    Tesuto.testp(Tesuto, str)
did not match C++ signature:
    testp(Tesuto {lvalue}, std::string*)
>>>                        
Run Code Online (Sandbox Code Playgroud)

python boost pointers arguments argument-passing

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

如何迭代张量的行,列和平面?

我试图在自定义运算符中迭代输出张量.到目前为止,我只看到了压平张量并迭代它的方法.

有没有更好的方法,所以我可以迭代行,列和平面?

auto output = output_tensor->flat<float>();

// I would like to iterate through the dimensions here
const int N = output.size();
for (int i = 0; i < N; i++) {
   output(i) = 0;
Run Code Online (Sandbox Code Playgroud)

c++ tensorflow

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

使用flyweight模式在位图对象之间共享位图

Hello堆栈溢出程序,我有一个设计使用flyweight模式来共享位图对象之间共享的位图,这些位图对象管理绘图操作等,并集成在gui库中.这是一个嵌入式设备,因此内存非常宝贵.目前,我已经完成了一个工作实现,它使用了一个轻量级的auto_ptr的std :: vector来计算用法.我知道这是一个坏主意,可能会泄漏,所以我重写了这一部分.我正在考虑使用boost :: shared_ptr.我的问题的关键是,如果没有使用,我希望释放位图.如果我有一个shared_ptr池,我最终加载了一次使用的位图.我正在考虑使用shared_ptr :: use_count()来删除位图,如果use_count()== 1.但是文档警告生成代码use_count().基本上问题是飞重模式与个别重物的释放.你认为有更好的方法吗?

c++ boost design-patterns

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

自定义分配器的帐户内存使用情况

我正在使用自定义分配器来计算几个容器中的内存使用情况.目前我使用静态变量来计算内存使用量.如何在不必重写分配器以使用不同的静态变量的情况下将此帐户分隔到多个容器中?


static size_t allocated = 0;


   template <class T>
   class accounting_allocator {
     public:
       // type definitions
       typedef T        value_type;
       typedef T*       pointer;
       typedef const T* const_pointer;
       typedef T&       reference;
       typedef const T& const_reference;
       typedef std::size_t    size_type;
       typedef std::ptrdiff_t difference_type;
       //static size_t allocated;

       // rebind allocator to type U
       template <class U>
       struct rebind {
           typedef accounting_allocator<U> other;
       };

       // return address of values
       pointer address (reference value) const {
           return &value;
       }
       const_pointer address (const_reference value) const {
           return &value; …
Run Code Online (Sandbox Code Playgroud)

c++ memory-management stl allocator

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

operator bool()转换为std :: string并与运算符std :: string()冲突

在类中声明运算符std :: string时,运算符bool()如何导致错误,并且还可以作为字符串的隐式转换?

#include <iostream>
#include <string>
using namespace std;

class Test {
public:
    operator std::string() { cout << "op string" << endl; return "whatever";}
    operator bool() { cout << "op bool" << endl; return true;}
};

int main(int argc, char *argv[]) {
    string s;
    Test t;
    s = t;
}
Run Code Online (Sandbox Code Playgroud)

c++ type-conversion

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

在C中通过套接字发送大文件

我正在为学校项目编写一个简单的FTP服务器.项目几乎完成,我唯一的问题是通过套接字向客户端发送文件.我无法写入超过200kb数据的套接字,成功下载小文件.谁能告诉我通过Linux套接字发送大文件的正确方法是什么?

提前致谢.

PS我使用C和32位linux,服务器在PORT模式下工作,一直使用低级开放,写入,读取等功能,如sendfile,send,sendto.

c sockets linux ftp

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

链接c ++流

我在考虑"链接"几个c ++ iostream,以便过滤两次输入.我正在使用gzstreams来读取zlib压缩文件,我正在考虑编写从流中读取并执行编码转换的流.也许通过传递一个打开的流作为构造函数参数...你怎么认为这可以做得最好?

c++ iostream

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

是否有一个很好的工具来调试基于Perl的Web应用程序?

是否有一个很好的工具来调试基于Perl的Web应用程序?输出到stderr或stdout不算作工具.

debugging perl

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

在Linux中的libstdc ++上调试功能?

我在VS2010的调试模式下运行我的代码,它收到了一个关于无效运算符的错误<这不是一个严格的弱顺序.有没有办法在Linux上的libstdc ++中捕获这些错误,或者这样的保守检查只是visual studio 2010的一个功能?

c++ linux stl visual-studio-2010

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

通知其他偏好活动已更改

我正在尝试将主要活动通知PreferenceActivity中的首选项更改,但是当我更改首选项时onSharedPreferenceChanged没有触发.

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener()
    {   
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
        {
            Log.d("Dict", "PreferenceChanged: " + key);
        }
    });
Run Code Online (Sandbox Code Playgroud)

java android

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

c ++ const符号膨胀链接文件

在C++中将const放在头文件中是合法的,通常C方式是将extern声明放在头部和定义中只在一个编译单元中,但在C++中,前一种技术导致二进制增加,因为链接时不删除符号(使用gnu ld和visual studio进行测试).有没有办法做这些事情?我只能想到一个定义或C方式,但后者可能会为更少的优化提供空间......


piotr@gominola:0:/tmp$ g++ -c b.cc
piotr@gominola:0:/tmp$ g++ -c a.cc
piotr@gominola:0:/tmp$ nm a.o | c++filt | grep COOK
0000000000000000 r AI_LIKE_COOKIES
piotr@gominola:0:/tmp$ nm b.o | c++filt | grep COOK
0000000000000000 r AI_LIKE_COOKIES
piotr@gominola:0:/tmp$ g++ -o a a.o b.o
piotr@gominola:0:/tmp$ nm a | c++filt | grep COOK
0000000000400610 r AI_LIKE_COOKIES
0000000000400618 r AI_LIKE_COOKIES



piotr@gominola:0:/tmp$ cat a.h
#ifndef a_h
#define a_h

//const double A = 2.0;
//extern const double AI_LIKE_COOKIES;
const double AI_LIKE_COOKIES = 5.0;

#endif
piotr@gominola:0:/tmp$ cat a.cc
#include "a.h" …
Run Code Online (Sandbox Code Playgroud)

c++ linker const constants

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

无法将__repr __/__ str__动态绑定到使用type创建的类

我在我自己的滚动Enum的蟒蛇类,我遇到了麻烦__str__,并__repr__能够正常工作,我究竟做错了什么?

In [2]: x = Enum(X=1, Y=2)

In [3]: x
Out[3]: common.utils.Enum

In [4]: str(x)
Out[4]: "<class 'common.utils.Enum'>"

In [5]: x.__repr__
Out[5]: <bound method type.reprfun of <class 'common.utils.Enum'>>

In [6]: x.__repr__()
Out[6]: 'Enum(Y=2, X=1)' 
Run Code Online (Sandbox Code Playgroud)

代码本身:

def Enum(*args, **kwargs):
    enums = dict(zip(args, range(len(args))), **kwargs)
    def reprfun(self):
        res = 'Enum(' +\
            ', '.join(map(lambda x: '{}={}'.format(x[0],x[1]), enums.items())) +\
            ')'
        return res

    reverse = dict((value, name) for name, value in enums.items())
    typedict = enums.copy()
    typedict['name'] = reverse
    instance …
Run Code Online (Sandbox Code Playgroud)

python types

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