1

I would like to translate this piece of code from C# to Powershell.

static unsafe void Copy(IntPtr source, int sourceOffset, IntPtr destination, int destinationOffset, int count)
{
    byte* src = (byte*)source + sourceOffset;
    byte* dst = (byte*)destination + destinationOffset;
    byte* end = dst + count;

    while (dst != end)
        *dst++ = *src++;
}

I' dont know how to deal with pointers in Powershell Can anybody help me?

5
  • 1
    More context is needed. Why do you think you even need this code in PowerShell? Note that you can always port C# code in its entirety using Add-Type (with -CompilerParameters to pass /unsafe to compile unsafe code), but there's possibly a better solution that requires no unsafe code at all. (For completeness: PowerShell has no native pointer types.) Commented Jan 22, 2018 at 14:44
  • doesn't this just do an array copy?...you can use the original byte array and do a copy - stackoverflow.com/questions/34833713/… Commented Jan 22, 2018 at 14:45
  • I assume this is to do with low-level graphics etc.? otherwise you can just do a straight array copy, if you're trying to do low level programming powershell really shouldn't be your tool of choice - but as Jeroen said you can compile unsafe code directly into Powershell types. Commented Jan 22, 2018 at 14:46
  • Thank you all for anwswer so fast. What i am trying to do, is a module that reads a folder full of font files and reads one by one, renders the font and creates a file either BMP or JPG. . I'm using as Sharpfont github.com/Robmaister/SharpFont to render the font file. In this files there is an example that has this piece of code. Commented Jan 22, 2018 at 15:09
  • And, yes this piece of code is related to low level graphics. Commented Jan 22, 2018 at 15:11

0

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.