What will be fastest way to create Vector3[] from sequential Memory Block?

I am trying to create a Vector3 from Memory Block. Currently what I have is a address of first location of data in memory (Pointer) and Length of data(which could easily go to few hundred thousands) .
At present I am doing it using for loop to increment pointer to fetch data for next locations and creating a new new entry after each 3 points in data in Vector3 Array;

For Example lets say this is a data in memory block :

1 2 3 4 5 6 7 8 9 10 11 12 13 15 

Output should be a a Vector3 which is create by following code manually:

 Vector3[] verticesData = new Vector3[] {
            new Vector3(1, 2, 3),
            new Vector3(4, 5, 6),
            new Vector3(7, 8, 9),
            new Vector3(10, 11, 12),
            new Vector3(13, 14, 15)    }; 

I am seeking for the fastest way to do it using code.

If you have the index, then there is no faster way. It is what algorithm calls O1, that is, as fast as can get.

You could optimize the loop as such:

for(int i = 0; i < length; i = i + 3) 


If you were iterating to find the item then you could optimize with various search algorithm whether your collection is ordered or not, bigger than a certain size or else or if you have a key to get the value.

In your case, none applies. At least, as far as I understand your usage of the collection.

Marshal.Copy() may be faster than a bunch of new Vector() calls.

I have to admit i’m new to this area of C#, and i’m not sure of the implications of the GCHandle.
My guess is that it creates a handle to some memory and also pins that memory in place,
and when the handle goes out of scope the memory is un-pinned.

Also i’m not entirely sure what you mean “Memory Block”.
If you have your memory block as an IntPtr, i think you’re in trouble.
There doesn’t seem to be an easy intPtr → intPtr Copy().
You might need to first copy your intPtrs into a float and then float into the intPtr for the Vec3s.

using UnityEngine;
using System.Runtime.InteropServices; // for Marshal
using System;                         // for IntPtr

public class foo : MonoBehaviour {
  void Start() {

  void doStuff() {
    float  [] vals = new float[] {1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f};
    Vector3[] vecs = new Vector3[vals.Length/3];

    GCHandle handleVs = GCHandle.Alloc(vecs, GCHandleType.Pinned);
    IntPtr pV = handleVs.AddrOfPinnedObject();

    Marshal.Copy(vals,0, pV, vals.Length); 

    for (int n = 0; n < vecs.Length; ++n) {
      Debug.Log("here we go: " + vecs[n].ToString() + "   " + vecs[n].magnitude);