Pass reference of object to a new Thread

后端 未结 4 382
天命终不由人
天命终不由人 2020-12-20 01:29

I have an object that contains a very large 3D-array of doubles and I need to start a new thread that need the data of this array, so I will either need to start a new threa

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-20 01:56

    10 thread ? how do you plan to maintain the data integrity of the _newObject ? Saying that copies will not be passed, only the reference will be used. If you going to call the method MyMethod(object MyObject) in 10 different threads will the MyObject be different objects ?? if not you are better off refractoring the method.

    Also you should remember that a thread is just a liner set of instructions to be executed. So just because of using multiple threads your object size will not increase in the memory.
    the very advantage of multi threading is to make use of different threads to process your instructions, and does not make copies of objects.

提交回复
热议问题