c# - Creating Subarray Without Copy and/or Allocation -


I am new to C #, and am wondering how to do the following:

I Create the array whose maximum number of elements I need to store:

  int [] myArray = new int [64000];   

I am passing this array in a third party API. In this API, they use the .length property to determine the number of elements. I do not want that because the array length is the maximum number, not the "active count" (i.e. the number of elements in use).

Keeping this in mind, create another array, whose size is equal to the active number? And, can it be done without copying and / or allocation? The memory I have allocated already is - what I want to do is that it indicates the sub-region of interest playing well with the third party API.

If the third party accepts a int [] , then passing your data The only way to copy will be.

An API can be easily designed where it is not necessary (i.e.: pass the number of elements, or use ArraySegment , etc. ), But if the API

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -