how to pass a malloc'd C string over to be managed by the GC
Kagamin
spam at here.lot
Thu Feb 28 08:21:53 UTC 2019
byte[] snappyCompress(in byte[] plaintext) {
import deimos.snappy.snappy;
size_t output_length =
snappy_max_compressed_length(plaintext.length);
byte[] output = new byte[output_length];
if(snappy_compress(cast(char*)plaintext.ptr, plaintext.length,
cast(char*)output.ptr, &output_length) == SNAPPY_OK) {
byte[] compressed = output[0..output_length];
// <---- do something magical here
return compressed;
}
assert(0);
}
Snappy works on bytes, not text, char is a wrong type there.
More information about the Digitalmars-d-learn
mailing list