Jump to content

What is scratchSurface ?


kalan
 Share

Recommended Posts

When writing a file type plugin there is scratchSurface in OnSave method. Can anyone tell me what it is and what's for?

The scratchSurface is a pixel buffer in the size of the document. You may use this buffer to render input (the document).

The application may save memory if you are using this buffer and not your own one.

  • Upvote 1

midoras signature.gif

Link to comment
Share on other sites

Yeah it's a pre-allocated buffer you can use for whatever. Memory allocations are a major source of failure/crashes, and therefore if you can avoid allocations it really helps. Since the "scratch surface" is already allocated, and since a buffer of the same size as the image is commonly needed for saving, it is provided to the FileType's OnSave() method.

You can't depend on the contents of the scratch surface being initialized, or uninitialized, to any particular pattern. So if you need to clear it out before writing other stuff to it, you should do so.

  • Upvote 1

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...