小编Tay*_*nli的帖子

使用> 2GB内存时,Cygwin g ++ x86_64分段故障(核心转储)

我用c ++编写了一个主筛程序,它使用~12GB ram来计算低于100,000,000,000(1000亿)的所有素数.

使用Visual Studio 2012(在为x64设置的项目中)以及64位linux上的g ++编译时,该程序工作正常.但是,当在Windows 7 Home Premium 64位上用cygwin64中的g ++编译时,尝试使用超过~2GB的ram(运行筛子> ~17,000,000,000)时会发生分段错误

我很确定它是作为64位进程运行的,因为任务管理器中的进程名称旁边没有*32.

代码:

#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
using namespace std;

long long sieve(long long n);

int main(int argc, char** argv) {
    const long long ONE_BILLION = 1000*1000*1000;
    if(argc == 2)
        cout << sieve(atol(argv[1])) << endl;
    else
        cout << sieve(ONE_BILLION * 100) << endl;
}

long long sieve(long long n) {
    vector<bool> bools(n+1);
    for(long long i = 0; i <=n; i++) 
        bools[i] = true;

    double …
Run Code Online (Sandbox Code Playgroud)

c++ memory cygwin g++ segmentation-fault

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

流 protoBuf 消息的设计模式

我想将 protobuf 消息流式传输到文件中。

我有一个 protobuf 消息

message car {
     ... // some fields
}
Run Code Online (Sandbox Code Playgroud)

我的 java 代码将创建此汽车消息的多个对象。

我应该如何将这些消息流式传输到文件中。

据我所知,有两种方法可以解决它。

  1. 有另一个消息,如汽车

    message cars {
      repeated car c = 1;
    }
    
    Run Code Online (Sandbox Code Playgroud)

    并使 java 代码创建一个汽车类型的对象,然后将其流式传输到文件中。

  2. 只需使用writeDelimitedTo函数将汽车消息适当地流式传输到单个文件中即可

我想知道使用 protobuf 进行流式传输的更有效方法是什么。

什么时候应该使用模式 1,什么时候应该使用模式 2?

这是我从https://developers.google.com/protocol-buffers/docs/techniques#large-data得到的

我不清楚他们想说什么。

大数据集

Protocol Buffers 不是为处理大消息而设计的。作为一般经验法则,如果您要处理每个大于 1 兆字节的消息,则可能是时候考虑替代策略了。

也就是说,Protocol Buffers 非常适合处理大型数据集中的单个消息。通常,大数据集实际上只是小块的集合,其中每个小块可能是一个结构化的数据。尽管 Protocol Buffers 不能一次处理整个集合,但使用 Protocol Buffers 对每个部分进行编码可以大大简化您的问题:现在您只需要处理一组字节字符串而不是一组结构。

Protocol Buffers 不包含对大型数据集的任何内置支持,因为不同的情况需要不同的解决方案。有时一个简单的记录列表就可以了,而有时您可能需要更像数据库的东西。每个解决方案都应该作为一个单独的库来开发,这样只有那些需要它的人才需要支付费用。

java design-patterns protocol-buffers

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

在AIX中Root Root Expiry时发出警报的脚本

我正在尝试在AIX中构建一个脚本,我计划将其作为cron作业运行.我希望脚本检查root密码是否会在10天后过期并触发电子邮件.我写了一个脚本来触发邮件,但我不知道如何编写root用于密码过期的脚本.

这是用于发送邮件的脚本.

#!/bin/sh
sendmail -t -F 'ABC ' -f 'abc@xyz.com' << test.mail
From: ABC <abc@xyz.com>
To:  def@xyz.com
Subject:
Password expired in 10 days
Run Code Online (Sandbox Code Playgroud)

这个脚本工作正常.

但我想要一个AIX脚本,它将在到期日期的10天内检查root密码到期.

shell aix

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

C#中的对象赋值

这是我在使用C#IList集合时遇到的问题

IList<MyClass> foo = new List<MyClass>();
var bar = new List<MyClass>();

foo.AddRange() // doesn't compile
bar.AddRange() // compile
Run Code Online (Sandbox Code Playgroud)

据我所知,在C#(与C++相反)中,当我们用这种语法创建一个对象时,对象类型得到右侧(赋值)而不是左侧(赋值).

我在这里想念一下!

EDIT

我仍然没有得到它,即使你的答案,foo和酒吧有相同的类型! 在此输入图像描述

c# object variable-assignment

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

使用可选参数

我有一个带有2个可选参数的方法.

public IList<Computer> GetComputers(Brand? brand = null, int? ramSizeInGB = null)
{
    return new IList<Computer>();
}
Run Code Online (Sandbox Code Playgroud)

我现在正尝试在其他地方使用此方法,我不想指定Brand参数,只是int但我使用此代码时遇到错误:

_order.GetComputers(ram);
Run Code Online (Sandbox Code Playgroud)

我收到的错误:

Error   1   The best overloaded method match for 'ComputerWarehouse.Order.GetComputers(ComputerWarehouse.Brand?, int?)' has some invalid arguments  C:\Users\avmin!\Documents\InnerWorkings Content\630dd6cf-c1a2-430a-ae2d-2bfd995881e7\content\T0062A2-CS\task\ComputerWarehouse\ComputerStore.cs 108 59  ComputerWarehouse
Error   2   Argument 1: cannot convert from 'int?' to 'ComputerWarehouse.Brand?'    C:\Users\avmin!\Documents\InnerWorkings Content\630dd6cf-c1a2-430a-ae2d-2bfd995881e7\content\T0062A2-CS\task\ComputerWarehouse\ComputerStore.cs 108 79  ComputerWarehouse
Run Code Online (Sandbox Code Playgroud)

c# optional-arguments

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

Python httplib.InvalidURL:非数字端口失败

我正在尝试在Python中打开需要用户名和密码的URL.我的具体实现如下:

http://char_user:char_pwd@casfcddb.example.com/......
Run Code Online (Sandbox Code Playgroud)

我得到以下错误吐到控制台:

httplib.InvalidURL: nonnumeric port: 'char_pwd@casfcddb.example.com'
Run Code Online (Sandbox Code Playgroud)

我正在使用urllib2.urlopen,但错误暗示它不理解用户凭据.它看到":"并期望端口号而不是密码和实际地址.我在这里做错了什么想法?

python urllib2 python-2.7

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

在String.Format中每两位数后添加逗号

我试图将数字格式化173910234.23为类似的东西17,39,10,234.23.这里只有第一个千位分隔符在三位数之后.但之后所有分隔符(,)都在两位数之后.我试过以下 -

double d = 173910234.23;
Console.WriteLine(string.Format("{0:#,##,##,###.00}", d));
Run Code Online (Sandbox Code Playgroud)

但它每三位数后输出逗号, 173,910,234.23

如何17,39,10,234.23使用格式string.Format

c# string formatting string-formatting

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

关于如何在Java中检索多个IP地址(如果我有多个网卡)的一些疑问?

我在检索客户端的ip时遇到以下两个问题.

我在一个类中创建了以下代码:

private static InetAddress thisIp;

static{
    try {
        thisIp  = InetAddress.getLocalHost();
        System.out.println("MyIp is: " + thisIp);
    } catch(UnknownHostException ex) {

    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:

1)前面的代码应检索客户端的IP地址,当我执行它时,它会打印以下消息:

MyIp是:andrea-virtual-machine/127.0.1.1

为什么它以andrea-virtual-machine /开头?(我在虚拟机上开发),这是一个问题吗?

2)通过这种方式,我只能检索一个IP地址,但我可以拥有多个网卡,这样我就可以拥有多个IP地址但多个IP地址

我该怎么做才能处理这种情况?我想把所有多个IP地址放入ArrayList

TNX

安德里亚

java networking ip-address

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

将文件写入android中的sdcard

我想在SD卡上创建一个文件.在这里我可以创建文件并将其读/写到应用程序,但我想要的是,文件应该保存在SD卡的特定文件夹中.我该怎么做FileOutputStream呢?

// create file
    public void createfile(String name) 
    {
        try
        {
            new FileOutputStream(filename, true).close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    // write to file

    public void appendToFile(String dataAppend, String nameOfFile) throws IOException 
    {
        fosAppend = openFileOutput(nameOfFile, Context.MODE_APPEND);
        fosAppend.write(dataAppend.getBytes());
        fosAppend.write(System.getProperty("line.separator").getBytes());
        fosAppend.flush();
        fosAppend.close();
    }
Run Code Online (Sandbox Code Playgroud)

android file android-sdcard

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

包命名约定

典型的情况是包前面有一个url,以防止冲突.

例如com.example.helloworld

您如何处理多部分TLD,例如co.nz?

  1. co.nz.example.helloworld,或
  2. nz.co.example.helloworld

思考?

java naming packages naming-conventions package

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