Is there a known time for which it is safe to reuse the buffer passed to PictureMarkerSymbol.SetSource?

3322
2
Jump to solution
04-29-2016 05:38 AM
carloscasanova
Deactivated User

PictureMarkerSymbol.SetSource Method

If it is possible, I would like to reuse the buffer. However, without knowing when the runtime is "done" reading from it, I don't know when it is safe.

I already verified that the buffer is not read from right away by writing to it immediately after setting it. Also, I saw that SetSource executes superfast (microseconds on my machine) lending further evidence that it is probably not doing any decoding right away.

Why do I want to reuse the buffer? I want to create less garbage (and hence GC pressure). I am attempting to use the PictureMarkerSymbol as a way to include general raster content generated on the fly. I am writing my own renderer that draws to a bitmap, encodes it, and then sends it to the runtime. Yes, this is very awkward, but the other runtime APIs do not satisfy my use case. See draw a million or more small lines. data set updated at 1-10Hz

0 Kudos
1 Solution

Accepted Solutions
MichaelBranscomb
Esri Frequent Contributor

Hi,

Are you able to write to the buffer once the call to SetSourceAsync completes?

Cheers

Mike

View solution in original post

0 Kudos
2 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi,

Are you able to write to the buffer once the call to SetSourceAsync completes?

Cheers

Mike

0 Kudos
carloscasanova
Deactivated User

Hi Mike, that did the trick.

After "awaiting", I can party on the buffer with no ill consequence.

Here is some more context in case others run into my problem:

I was using a MemoryStream. I could only get it to work with SetSource and not with SetSourceAsync because I forgot to set the seek point on the stream to the beginning before passing it to SetSourceAsync. From my testing, the operation is async with both SetSource and SetSourceAsync. SetSourceAsync just allows to monitor when that async operation completes. Because the operation is async, I noticed an occasional error when I would write to the stream right away after passing it to SetSource because I was writing data that the runtime was reading at the same time.