Graphics and Unmanaged buffer

In examples of user interface, we can see these lines:

        var ptr = Memory.UnmanagedMemory.Allocate(640 * 480 * 2);
        var data = Memory.UnmanagedMemory.ToBytes(ptr, 640 * 480 * 2);

I suppose it is to use unmanaged memory to display application, but how application can know data is buffer to display ? It isn’t used after. Is Something missing in example ?

Unmanaged Memroy serves 2 things:

  1. For graphics: It is automatic. There is nothing for you to do!
  2. For your application if you need very large buffers and that is what you show in your example.

So in code (in user-interface.md):

        var screen = Graphics.FromHdc(display.Hdc);
        var controller = I2cController.GetDefault();
        var ptr = Memory.UnmanagedMemory.Allocate(640 * 480 * 2);
        var data = Memory.UnmanagedMemory.ToBytes(ptr, 640 * 480 * 2);

ptr and data are unused ? (As screen Which use graphics use already unmanaged)
As data is never used again.

We were probably testing it but those lines should not be there! We will fix the docs.

1 Like

you dont need those lines.

2 Likes

I understand better ! :wink: