socketry / nio4r

Cross-platform asynchronous I/O primitives for scalable network clients and servers.
Other
967 stars 86 forks source link

Quick (possible) fix for #241 + consistent global C formatting / styling #243

Closed boazsegev closed 4 years ago

boazsegev commented 4 years ago

So, after a lot of work in the wrong direction, I think I found only one reference that GC moves and creates a "dangling pointer"....

If you don't want to merge the automatic C code formatting (which would help collaboration,. IMHO), you can just fix the monitor.c file so NIO_Monitor_mark isn't empty, but rather:

static void NIO_Monitor_mark(struct NIO_Monitor *monitor)
{
    rb_gc_mark(monitor->self); /* prevent GC.compact from moving the memory */
}

After fixing this one line, the tests don't crash on my computer.

P.S.

I was impressed reading through the code base. The code is clean and succinct.

I probably would have coded things way more complicated since I would have avoided any Ruby objects in the C layer and would have used local memory allocators for the C layer objects (so they have a separate memory address pool from the main allocator as well as more locality)...

Maybe it's a good thing my long work was tossed in the bean, I actually finished adding a local memory allocator for the C layer in a different branch (enabled with ENV['NIO_MEMORY_POOL'] = "1") 😅

ioquatix commented 4 years ago

Please make a single commit to address the issue without "styling fixes".

boazsegev commented 4 years ago

Sure @ioquatix , it's your show, I'll do as you ask.