Tag: C#的

C ++ 0x线程中断

根据C ++ 0x最终草案,没有办法请求线程终止。 这就是说,如果需要,我们需要实施一个自己动手的解决scheme。 另一方面,boost :: thread提供了一种以安全方式中断线程的机制。 在你看来,最好的解决scheme是什么? devise自己的合作“中断机制”还是本土化?

PTHREAD_MUTEX_INITIALIZER vs pthread_mutex_init(&mutex,param)

有什么区别吗? pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; 要么 pthread_mutex_t lock; pthread_mutex_init ( &lock, NULL); 如果我只使用第一种方法,我是否足够安全? 注:我的问题主要是指非常小的程序,至多我会做的是连接几个客户端到服务器,并解决他们的查询与工作线程。

为什么不能std :: ostream被移动?

显然,stream不能被复制。 应该有可能移动stream。 根据27.9.1.11 [ofstream.cons]第4段,可以移动构造std::ofstream ( std::ifstream , std::fstream和std::*stringstream变种也是如此)。 例如: #include <iostream> #include <fstream> #include <string> std::ofstream makeStream(std::string const& name) { return std::ofstream(name); } int main() { std::ofstream out{ makeStream("example.log") }; } 试图移动一个std::ostream ,例如,有一个工厂函数创build一个std::ofstream ,一个std::ostringstream ,或根据作为parameter passing的URN的其他stream不起作用。 std::ostream (好的,类模板std::basic_ostream真的)有一个按照27.7.3.1 [ostream] protected移动构造函数。 为什么不能std::ostream被移动本身?

C#应用程序中的资源和embedded式资源有什么区别?

我应该什么时候使用其中一个? 我希望在我的应用程序中使用的所有文件(图像,声音,xml文件等)都位于.exe文件的内部,因此我不会部署大量文件夹和文件。 谢谢(你的)信息。

为什么C#multidimensional array不能实现IEnumerable <T>?

我刚刚注意到,C#中的multidimensional array并没有实现IEnumerable<T> ,而是实现了IEnumerable 。 对于一维数组, IEnumerable<T>和IEnumerable都被实现。 为什么这个区别? 如果一个multidimensional array是IEnumerable ,当然它也应该实现通用版本? 我注意到这一点,因为我试图在multidimensional array上使用扩展方法,除非使用Cast<T>或类似的方法,否则失败。 所以我可以肯定地看到使multidimensional array实现IEnumerable<T>的一个参数。 为了在代码中阐明我的问题,我期望下面的代码打印true四次,而实际上打印true , false , true , true : int[] singleDimensionArray = new int[10]; int[,] multiDimensional = new int[10, 10]; Debug.WriteLine(singleDimensionArray is IEnumerable<int>); Debug.WriteLine(multiDimensional is IEnumerable<int>); Debug.WriteLine(singleDimensionArray is IEnumerable); Debug.WriteLine(multiDimensional is IEnumerable);

在C ++中使用const重载是什么?

在C ++中,函数的签名部分取决于它是否为const。 这意味着一个类可以有两个具有相同签名的成员函数,但一个是const而另一个不是。 如果你有这样的类,那么编译器会根据你调用的对象决定调用哪个函数:如果它是类的常量实例,函数的const版本将被调用; 如果该对象不是const,则另一个版本将被调用。 在什么情况下你可能想利用这个function?

是std :: stoi实际上安全使用?

我和一个关于std::stoi的垮台的人进行了一次可爱的交谈。 说穿了,它内部使用std::strtol ,并抛出,如果报告错误。 据他们说,虽然std::strtol不应该为"abcxyz"input"abcxyz" ,导致stoi不会抛出std::invalid_argument 。 首先,这里有两个程序在GCC上testing了这些案例的行为: 与strtol Stoi旅馆 他们都在"123"上显示成功,在"abc"上显示失败。 我看了标准拉更多的信息: §21.5 Throws: invalid_argument if strtol, strtoul, strtoll, or strtoull reports that no conversion could be performed. Throws out_of_range if the converted value is outside the range of representable values for the return type. 这总结了依靠strtol的行为。 现在怎么样? 我在C11草稿中发现了这个: §7.22.1.4 If the subject sequence is empty or […]

属性声明中的“新”关键字在c#

我已经得到一个.net项目来维护。 我只是浏览代码,我注意到了一个属性声明: public new string navUrl { get { return …; } set { … } } 我想知道new修饰符对属性做了什么?

这个expression意味着什么?为什么要编译?

打字错误后,编译和执行下列expression式(简化): if((1 == 2) || 0 (-4 > 2)) printf("Hello"); 当然,0不应该在那里。 为什么要编译,这个expression意味着什么? 原来的(简体)应该是这样的: if((1 == 2) || (-4 > 2)) printf("Hello"); 这没有一个编译: if((1 == 2) || true (-4 > 2)) printf("Hello"); if((1 == 2) || 1 (-4 > 2)) printf("Hello"); if((1 == 2) || null (-4 > 2)) printf("Hello");

检查一个指针是否被分配了内存

我们可以检查传递给一个函数的指针是否被分配了内存或不在C中? 我有自己的C函数,它接受一个字符指针 – buf [指向缓冲区的指针]和size – buf_siz [buffer size]。 实际上,在调用这个函数之前,用户必须创build一个缓冲区并为其分配buf_siz的内存。 由于用户有可能忘记进行内存分配,只需将指针传递给我的函数,我想检查一下。 那么有没有什么办法可以检查我的函数来查看指针是否真的被分配了buf_siz的内存量。 编辑1:似乎没有标准库检查它..但有没有任何肮脏的黑客检查它..? 编辑2:我知道我的function将被一个好的C程序员使用…但我想知道我们是否可以检查或不..如果我们可以,我想听听它.. 结论:所以不可能检查一个特定的指针是否在内存中分配或者不在一个函数中