@@ -680,7 +680,9 @@ idType HNSWIndex<DataType, DistType>::mutuallyConnectNewElement(
680680 neighbors_bitmap[neighbor_neighbors[j]] = true ;
681681 }
682682
683- idType removed_links[sz_link_list_other + 1 ];
683+ auto removed_links_alloc =
684+ this ->getAllocator ()->allocate_unique ((sz_link_list_other + 1 ) * sizeof (idType));
685+ auto removed_links = static_cast <idType *>(removed_links_alloc.get ());
684686 size_t removed_links_num;
685687 removeExtraLinks (ll_other, candidates, Mcurmax, neighbor_neighbors, neighbors_bitmap,
686688 removed_links, &removed_links_num);
@@ -755,7 +757,9 @@ void HNSWIndex<DataType, DistType>::repairConnectionsForDeletion(
755757
756758 size_t Mcurmax = level ? maxM_ : maxM0_;
757759 size_t removed_links_num;
758- idType removed_links[neighbour_neighbours_count];
760+ auto removed_links_alloc =
761+ this ->getAllocator ()->allocate_unique (neighbour_neighbours_count * sizeof (idType));
762+ idType *removed_links = static_cast <idType *>(removed_links_alloc.get ());
759763 removeExtraLinks (neighbour_neighbours_list, candidates, Mcurmax, neighbour_neighbours,
760764 neighbour_orig_neighbours_set, removed_links, &removed_links_num);
761765
@@ -1166,11 +1170,11 @@ int HNSWIndex<DataType, DistType>::appendVector(const void *vector_data, const l
11661170
11671171 idType cur_c;
11681172
1169- DataType normalized_blob[ this ->dim ]; // This will be use only if metric == VecSimMetric_Cosine
1173+ auto normalized_blob = this ->getAllocator ()-> allocate_unique ( this -> dim * sizeof (DataType));
11701174 if (this ->metric == VecSimMetric_Cosine) {
1171- memcpy (normalized_blob, vector_data, this ->dim * sizeof (DataType));
1172- normalizeVector (normalized_blob, this ->dim );
1173- vector_data = normalized_blob;
1175+ memcpy (normalized_blob. get () , vector_data, this ->dim * sizeof (DataType));
1176+ normalizeVector (static_cast <DataType *>( normalized_blob. get ()) , this ->dim );
1177+ vector_data = normalized_blob. get () ;
11741178 }
11751179
11761180 {
@@ -1392,11 +1396,11 @@ VecSimQueryResult_List HNSWIndex<DataType, DistType>::topKQuery(const void *quer
13921396
13931397 void *timeoutCtx = nullptr ;
13941398
1395- DataType normalized_blob[ this ->dim ]; // This will be use only if metric == VecSimMetric_Cosine.
1399+ auto normalized_blob = this ->getAllocator ()-> allocate_unique ( this -> dim * sizeof (DataType));
13961400 if (this ->metric == VecSimMetric_Cosine) {
1397- memcpy (normalized_blob, query_data, this ->dim * sizeof (DataType));
1398- normalizeVector (normalized_blob, this ->dim );
1399- query_data = normalized_blob;
1401+ memcpy (normalized_blob. get () , query_data, this ->dim * sizeof (DataType));
1402+ normalizeVector (static_cast <DataType *>( normalized_blob. get ()) , this ->dim );
1403+ query_data = normalized_blob. get () ;
14001404 }
14011405 // Get original efRuntime and store it.
14021406 size_t ef = ef_;
@@ -1509,11 +1513,11 @@ VecSimQueryResult_List HNSWIndex<DataType, DistType>::rangeQuery(const void *que
15091513 }
15101514 void *timeoutCtx = nullptr ;
15111515
1512- DataType normalized_blob[ this ->dim ]; // This will be use only if metric == VecSimMetric_Cosine
1516+ auto normalized_blob = this ->getAllocator ()-> allocate_unique ( this -> dim * sizeof (DataType));
15131517 if (this ->metric == VecSimMetric_Cosine) {
1514- memcpy (normalized_blob, query_data, this ->dim * sizeof (DataType));
1515- normalizeVector (normalized_blob, this ->dim );
1516- query_data = normalized_blob;
1518+ memcpy (normalized_blob. get () , query_data, this ->dim * sizeof (DataType));
1519+ normalizeVector (static_cast <DataType *>( normalized_blob. get ()) , this ->dim );
1520+ query_data = normalized_blob. get () ;
15171521 }
15181522
15191523 double epsilon = epsilon_;
0 commit comments