libcouchbase C API without callbacks?

Since v1 of the API, the C libcouchbase has required errors and get results to call back to a function, and most other language APIs do this but PHP doesn't. Why is this? With MySQL you can just make function calls and get results back. I'm trying to use libcouchbase in a C++ app but I need to be able to get a direct result back to use with class instances but I can't do this because the API requires a static callback where I can't pass the pointer of my class instance to. As said, the PHP version allows a direct $value = $cb->Get(key) so why can't the other libraries at least have this option available?

Desperately trying to get rid of MySQL in favor of Couchbase but this is a huge roadblock.

1 Answer

« Back to question.

The primary reason we're not returning the object is that it would normally just require extra memory copying. With the callback method you can pass in the object you want to populate as the command cookie, and in the callback copy the data where you want to do it directly from the internal buffers in libcouchbase.

If libcouchbase should copy the data into another buffer and return that to you we would have a new challenge figuring out who is responsible for maintaining that buffer and do the free. If the application use a special memory manager etc it would also be complex to do that.

Hope this helps.

Cheers,
Trond