2

Just trying to get a feeler here for what is the best practice for accessing native arrays.

Specifically what I'd like to know is if there is any overhead involved when accessing them via native pointers for arrays of floats or ints.

Am I fine just indexing into my native arrays via pointer arithmetic or should I be copying the entire native block into a managed array and than accessing the managed array?

As it stands I have things setup so that my managed class holds a native pointer. The manage class than retrieves underlying data via the native pointer. This seems reasonable, but I am unsure of what type of interop might be going on behind the scenes.

I appreciate any input.

Snippet Added.

From API:

#define rtArrayItemP(a, pos) (a)->data[(pos) * (a)->width + (a)->element]

My Code:

template<typename T1, typename T2> public ref class ArrayW
{
internal:
    ArrayW(T2* arr)
    {
        _arr = arr;
    }

    property T2* Array
    {
        T2* get()
        {
            return _arr;
        }
    }

protected:
    T1 getarrayelement(int index)
    {
        return rtArrayItemP(_arr, index);
    }

    void setarrayelement(int index, T1 value)
    {
        rtArrayItemP(_arr, index) = value;
    }
    T2* _arr;
};
4

0 に答える 0