Main Site Documentation

RLP By Ref


#1

Is there a way to pass a variable to RLP by reference? I’m assuming there probably is and I’m just not well versed enough to know it.

I have several byte arrays that I need RLP to be able to manipulate, but I can pass the arrays themselves in because they exceed the RLP memory space.

Oh and BTW after one of you awesome FEZzers answer I’ll have rockin new video for you to all see. :smiley:


#2

A byte array is passed to RLP as if you were passing a pointer. You can modify them and you can give RLP more memory this way


#3

What Gus is saying is that you should be able to pass the first index of the array (instead of the array) and the length, and then just increment the pointer by one in your RLP code.

So your function would look like:


void DoSomething(byte firstByte, int length)
{
    byte* arrayAddress = &firstByte;

    for (int i = 0; i < length; i++)
    {
        //Manipulate the byte here
       arrayAddress++;
    }
}

In the full framework there are ways to get native pointers to things, but I’m not sure if it’s supported by the microframework. If that’s the case, then your function prototype can just be:

void DoSomething(byte *array, int length)

And in C# you can use the addressof operator just like in c++, so you would pass your array like this:


byte[] myArray = new byte[100];
unsafe
{
    DoSomething(&myArray, myArray.Length);
}

C# (full framework at least) supports pointers and addressof operators natively, but must be wrapped in an Unsafe block.


#4

What I meant is that RLP passes a byte array’s pointer and not a copy of the array. Changes in RLP on that array will be reflected on same array in c#


#5

Awesome, thanks for the info! I’ll play around with this as soon as I can. :slight_smile: