Browse Source

add free in test

master
Ethan 1 year ago
parent
commit
113bf2f707
3 changed files with 15 additions and 7 deletions
  1. +1
    -1
      inc/utils.h
  2. +10
    -5
      src/test.c
  3. +4
    -1
      src/utils.c

+ 1
- 1
inc/utils.h View File

@ -5,4 +5,4 @@ typedef struct {
} VecData;
float vec_dist(VecData x, VecData y);
VecData* fvecs_read(const char* filename, int* bounds);
VecData* fvecs_read(const char* filename, int* bounds, int* num);

+ 10
- 5
src/test.c View File

@ -4,13 +4,18 @@
int main() {
int num = 0;
VecData* vecs = fvecs_read("../dataset/siftsmall_base.fvecs", NULL, &num);
printf("num: %d\n", num);
VecData* vecs = fvecs_read("../dataset/siftsmall_base.fvecs", NULL);
for (int i = 0; i < 10000; i++) {
printf("%f\n", vecs[i].vector[0]);
// Free memory
for (int i = 0; i < num; i++) {
free(vecs[i].vector);
}
free(vecs);
return 0;
}
}

+ 4
- 1
src/utils.c View File

@ -14,7 +14,7 @@ float vec_dist(VecData x, VecData y) {
return sqrt(sum);
}
VecData* fvecs_read(const char* filename, int* bounds) {
VecData* fvecs_read(const char* filename, int* bounds, int* num) {
FILE* fid = fopen(filename, "rb");
if (fid == NULL) {
fprintf(stderr, "I/O error : Unable to open the file %s\n", filename);
@ -66,5 +66,8 @@ VecData* fvecs_read(const char* filename, int* bounds) {
fclose(fid);
if (num != NULL) {
*num = n;
}
return v;
}

Loading…
Cancel
Save