out

Boxing and unboxing when using out and ref parameters

别来无恙 提交于 2019-12-03 22:41:50
Does boxing/unboxing occur when a method accepts an out/ref parameter of a ValueType? For ref Keyword Its already mentioned on MSDN that : Do not confuse the concept of passing by reference with the concept of reference types. The two concepts are not the same. A method parameter can be modified by ref regardless of whether it is a value type or a reference type. There is no boxing of a value type when it is passed by reference. As for out keyword: The out keyword causes arguments to be passed by reference . This is like the ref keyword, except that ref requires that the variable be

Returning two values, Tuple vs 'out' vs 'struct'

北城余情 提交于 2019-12-03 04:00:45
问题 Consider a function which returns two values. We can write: // Using out: string MyFunction(string input, out int count) // Using Tuple class: Tuple<string, int> MyFunction(string input) // Using struct: MyStruct MyFunction(string input) Which one is best practice and why? 回答1: They each have their pros and cons. Out parameters are fast and cheap but require that you pass in a variable, and rely upon mutation. It is almost impossible to correctly use an out parameter with LINQ. Tuples make

Why can't iterator methods take either 'ref' or 'out' parameters?

这一生的挚爱 提交于 2019-12-03 03:33:28
问题 I tried this earlier today: public interface IFoo { IEnumerable<int> GetItems_A( ref int somethingElse ); IEnumerable<int> GetItems_B( ref int somethingElse ); } public class Bar : IFoo { public IEnumerable<int> GetItems_A( ref int somethingElse ) { // Ok... } public IEnumerable<int> GetItems_B( ref int somethingElse ) { yield return 7; // CS1623: Iterators cannot have ref or out parameters } } What's the rationale behind this? 回答1: C# iterators are state machines internally. Every time you

Returning two values, Tuple vs 'out' vs 'struct'

百般思念 提交于 2019-12-02 17:22:25
Consider a function which returns two values. We can write: // Using out: string MyFunction(string input, out int count) // Using Tuple class: Tuple<string, int> MyFunction(string input) // Using struct: MyStruct MyFunction(string input) Which one is best practice and why? They each have their pros and cons. Out parameters are fast and cheap but require that you pass in a variable, and rely upon mutation. It is almost impossible to correctly use an out parameter with LINQ. Tuples make collection pressure and are un-self-documenting. "Item1" is not very descriptive. Custom structs can be slow

Why can't iterator methods take either 'ref' or 'out' parameters?

风流意气都作罢 提交于 2019-12-02 17:02:49
I tried this earlier today: public interface IFoo { IEnumerable<int> GetItems_A( ref int somethingElse ); IEnumerable<int> GetItems_B( ref int somethingElse ); } public class Bar : IFoo { public IEnumerable<int> GetItems_A( ref int somethingElse ) { // Ok... } public IEnumerable<int> GetItems_B( ref int somethingElse ) { yield return 7; // CS1623: Iterators cannot have ref or out parameters } } What's the rationale behind this? C# iterators are state machines internally. Every time you yield return something, the place where you left off should be saved along with the state of local variables

Mysql - Stored procedure OUT variable return null

不打扰是莪最后的温柔 提交于 2019-12-02 13:48:17
问题 My Table Structure is: DROP TABLE IF EXISTS `child`; CREATE TABLE `child` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; DROP TABLE IF EXISTS `map_parent_child`; CREATE TABLE `map_parent_child` ( `id` int(11) NOT NULL AUTO_INCREMENT, `parent_id` int(11) NOT NULL, `child_id` int(11) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `unique_parent_child` (`parent_id`,`child_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; DROP

Java Arry Index Out of Bound Exception

懵懂的女人 提交于 2019-12-02 11:16:31
I have been working on this basic java program when I need to store 5 user entered values into an array, send it to a method, and find and display the lowest value. The program is simple enough, and it runs, but when I enter the last number, I get the error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4 at minNumber.main(minNumber:14) Help? import java.util.*; class minNumber { public static void main(String args[]){ Scanner input = new Scanner(System.in); int numberArray[] = new int[4]; int findLowest; for (int i = 0; i <= numberArray.length; i++){ System.out.println(

eclipse中JVM的内存问题,解决堆空间不足的问题

删除回忆录丶 提交于 2019-12-02 08:33:42
-vmargs -Xms128M -Xmx512M -XX:PermSize=64M -XX:MaxPermSize=128M 这里有几个问题: 1. 各个参数的含义什么? 2. 为什么有的机器我将-Xmx和-XX:MaxPermSize都设置为512M之后Eclipse可以启动,而有些机器无法启动? 3. 为何将上面的参数写入到eclipse.ini文件Eclipse没有执行对应的设置? 下面我们一一进行回答 1. 各个参数的含义什么? 参数中-vmargs的意思是设置JVM参数,所以后面的其实都是JVM的参数了,我们首先了解一下JVM内存管理的机制,然后再解释每个参数代表的含义。 堆(Heap)和非堆(Non-heap)内存 按照官方的说法:“Java 虚拟机具有一个堆,堆是运行时数据区域,所有类实例和数组的内存均从此处分配。堆是在 Java 虚拟机启动时创建的。”“在JVM中堆之外的内存称为非堆内存(Non-heap memory)”。可以看出JVM主要管理两种类型的内存:堆和非堆。简单来说堆就是Java代码可及的内存,是留给开发人员使用的;非堆就是JVM留给自己用的,所以方法区、JVM内部处理或优化所需的内存(如JIT编译后的代码缓存)、每个类结构(如运行时常数池、字段和方法数据)以及方法和构造方法的代码都在非堆内存中。 堆内存分配 JVM初始分配的内存由-Xms指定

Mysql - Stored procedure OUT variable return null

大兔子大兔子 提交于 2019-12-02 04:22:20
My Table Structure is: DROP TABLE IF EXISTS `child`; CREATE TABLE `child` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; DROP TABLE IF EXISTS `map_parent_child`; CREATE TABLE `map_parent_child` ( `id` int(11) NOT NULL AUTO_INCREMENT, `parent_id` int(11) NOT NULL, `child_id` int(11) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `unique_parent_child` (`parent_id`,`child_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; DROP TABLE IF EXISTS `parent`; CREATE TABLE `parent` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar

Capturing Audio Out

﹥>﹥吖頭↗ 提交于 2019-12-01 11:06:10
I want to capture all audio that is played to the user (all sounds together). Currently I'm working on Windows but it would be nice if the code was cross-platform (but not necessarily). Is it possible to do it with OpenAL? How? Code examples would be great. Language: C++ The only way to do this I believe is to create a replacement audio device driver that receives all audio requests, and then forwards them to the original device driver. There are a number of existing applications that work in this way including Freecorder , MP3myMP3 Recorder , SoundTap and Wondershare to name but a few (Google