msgpack-ruby
msgpack-ruby copied to clipboard
Use TypedData structs
The API is a bit more modern and open the door to several features such as memsize
, write barriers etc.
The main addition for now is support for memsize_of
:
>> ObjectSpace.memsize_of(f)
=> 2128
Note: Buffer
is still "untyped" because there is actually two types of buffer. Some with their own memory region, and in charge of freeing it, and some that point to the Unpacker
memory and need to not have a free
function.
For now I don't see how to do this with TypedData
structs.
Honestly speaking, I have almost no idea about TypeData
structs.
Could you point any kind of documents or texts we can learn it?
Could you point any kind of documents or texts we can learn it?
I'll try to find some more, the MRI C API is unfortunately very undocumented. In the meantime there's this ticket (in japanese so I don't know what it says): https://bugs.ruby-lang.org/issues/1637
A few more resources:
- The official extension doc: https://github.com/ruby/ruby/blob/master/doc/extension.rdoc
- Some unofficial (but generally more helpful) API guide: https://silverhammermba.github.io/emberb/c/#data
- A somewhat "tutorially" description of it: https://blog.peterzhu.ca/ruby-c-ext-part-7/
We should get on and do this - the old data API is very deprecated, and causes problems for future GC.
Agreed. I may need to do it one class at a time though because this was too big of a change for me.
I'll try to get back at this this week.
This has been split in 3 distinct PRs, one for each type.