Using Action <PointerClass *> as an Argument

I am creating a performance-critical application that implements image manipulation. I use some pixel pointers using my structure with a name Pixelto do some processing. I have many pieces of code that iterate over all the bitmap image data, and to reuse the code and modularity, I am developing a method that will act and apply it to all pixels of the image (for example, to the map function). However, when I write Action<Pixel*>, Visual Studio complains about code saying that the type Pixel*cannot be used as an argument to the type. The whole class is in context unsafe, and I use pointers Pixeleverywhere, but I just can't use a pixel pointer as an action pattern class.

I can use it Action<IntPtr>, but I will need to convert it to the corresponding pointers inside the method body in EVERY iteration, which will kill the whole idea of ​​"critical performance".

+5
source share
2 answers

Nothing seems to make you use it Action<T>, so you can create your own delegate type. I have not found a way to do this in a general way, but it works:

unsafe delegate void PixelAction(Pixel* ptr);

, , , . , , , ( ) , Reflection.Emit CodeDOM.

+8

, .

, Action <IntPtr> , , , . , , .

EDIT: , (CS0208)

, Action <T> :

delegate void PointerAction<T>(T* ptr);

+1

All Articles