This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Latest win32-api enhancement - 'S' prototypes
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
The latest installment of the win32-api library will support 'S' (string) prototypes, which will be a distinct entity from 'P' (pointer) prototypes. Users can use 'S' for const char* and 'P' for pass by reference char* buffers. Why the distinction? A few reasons.
First, with pointers we always have to assume mutability. That means making an internal rb_str_modify() call on every pointer, even when it wasn't necessary. That, in turn, lead to some subtle issues, like the fact that you couldn't pass frozen strings to API calls.
Second, it's faster. About 33% faster in my benchmarks, because we don't have to worry that the string will be modified. I don't want to exaggerate the benchmarks, though. The reality is that this will mostly only benefit the MSVCRT functions. Still, it's nice.
Third, I think it will be easier to deal with for other implementations like JRuby and IronRuby, if I ever get around to porting this library. I have a partially complete JRuby version, but references are a pain.