coolbutuseless,
@coolbutuseless@fosstodon.org avatar

Is there a blessed way to create a RAWSXP from an existing chunk of memory within C?

Specifics:

  • The memory is already allocated elsewhere
  • I don't want to use memcpy, just wrap the memory where it is such that the RAWSXP points to it.
  • I don't want the garbage collector to know about it - I will free the memory myself later.
  • It still has to be valid RAWSXP that I can use in R

This is a bit of a callback to this post: https://fosstodon.org/@coolbutuseless/111956983679205597

coolbutuseless,
@coolbutuseless@fosstodon.org avatar

The reason I want to wrap existing memory in a raw vector:

  • R does not expose handling of "connections" within C
  • In C, I have existing memory to write to an R connection
  • I have to alloc a RAWSXP of the appropriate size & copy the memory into it
  • Then call out to R (from C) to the function writeBin()
  • And writeBin() is just going to unbox this & use the raw memory

So a 'fake' SEXP header would save a bit of unnecessary overhead & copying

And there is lots of data to write!

#RStats

coolbutuseless,
@coolbutuseless@fosstodon.org avatar

Obviously, I'm going to try and write it, but I was hoping it was a known thing that was already exposed in the R API.

#RStats

exa,
@exa@mastodon.online avatar

@coolbutuseless how does writeBin handle the connection? (Most likely it is C code already that can be copypasted or so, or perhaps at least called with lighter parameters than SEXPs)

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • GTA5RPClips
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • tacticalgear
  • cubers
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • osvaldo12
  • ngwrru68w68
  • kavyap
  • InstantRegret
  • JUstTest
  • everett
  • Durango
  • cisconetworking
  • khanakhh
  • ethstaker
  • tester
  • anitta
  • Leos
  • normalnudes
  • modclub
  • megavids
  • provamag3
  • lostlight
  • All magazines