Copy index file content to c memory (#16162)

Might be the root cause of #15896
The index content bytes were passed via unsafe.Pointer,
which shall be copy to cpp managed memory inmediately

This solution might cause a lot of memory consumption.
Maybe we need to store the index bytes in cpp memory in the first place.

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2022-03-24 14:55:25 +08:00 committed by GitHub
parent 63a71e247a
commit 661469445c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,7 +47,9 @@ AppendIndexBinary(CBinarySet c_binary_set, void* index_binary, int64_t index_siz
auto binary_set = (milvus::knowhere::BinarySet*)c_binary_set;
std::string index_key(c_index_key);
uint8_t* index = (uint8_t*)index_binary;
std::shared_ptr<uint8_t[]> data(index, [](void*) {});
uint8_t* dup = new uint8_t[index_size]();
memcpy(dup, index, index_size);
std::shared_ptr<uint8_t[]> data(dup);
binary_set->Append(index_key, data, index_size);
status.error_code = Success;