2

In my C# code, I have constructed four arrays of data:

double[] values;
DateTime[] timestamps;
long[] qualities;
long[] reasons;

These arrays need to be passed to an external API. The API method call is somewhat indirect; its signature looks like invokeApiMethod(string apiMethodName, Object[] apiMethodParams).

In this case, the external API method call expects four arrays of the kind that I have already constructed.

If I construct the Object[] using the following code:

Object[] apiMethodParams = { values, timestamps, qualities, reasons };

Will this result in all four existing arrays being copied into a large contiguous block of new memory? Or will C# just pass an array of references to the existing arrays to the external API?

3 Answers 3

4

Will this result in all four existing arrays being copied into a large contiguous block of new memory? Or will C# just pass an array of references to the existing arrays to the external API?

The latter. It will be an array of four elements, each element of which is a reference. The values of values, timestamps etc are just references to arrays.

Note that you may want to take a copy of some or all of the arrays if the external API modifies the array contents, and you want the original values - but that won't happen automatically.

Sign up to request clarification or add additional context in comments.

Comments

1

http://www.mbaldinger.com/post/C-reference-types-are-passed-by-value!.aspx

http://answers.yahoo.com/question/index?qid=20090105141923AAt63hD

In case you need to pass different array, you need to clone/copy it and then pass the cloned/copied array

Comments

0

They are references. Copying and creating uses the "new" keyword.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.