summaryrefslogtreecommitdiff
diff options
authorJesper Nilsson <[email protected]>2013-10-10 11:09:52 +0200
committerJesper Nilsson <[email protected]>2013-10-10 11:12:16 +0200
commit2aad67171b36c94ea8f391ecea2834df0cb9f953 (patch)
tree3c476f148baa602e5d8c6295ff38425322902181
parent401230026c26a327328fcf394a7bc2a2e5cb594d (diff)
downloadaxis-profile-master.tar.gz
Allocate space in larger chunks when reading mapsHEAD3.3.5master
A normal file-map is always bigger than 512 bytes, bump the buffer to 10k to avoid lots of reallocations. Signed-off-by: Jesper Nilsson <[email protected]>
-rw-r--r--file.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/file.c b/file.c
index 1b90f5d..ccb3d36 100644
--- a/file.c
+++ b/file.c
@@ -60,10 +60,12 @@ char *get_pid_file(unsigned int pid, const char *filename)
return get_proc_file(proc_file);
}
+#define MAPS_FILESIZE 20480
+
char *get_proc_file(const char *filename)
{
FILE *f;
- size_t buffer_size = MAX_STRING_LEN;
+ size_t buffer_size = MAPS_FILESIZE;
char command[MAX_STRING_LEN];
char *file = malloc(buffer_size + 1);
size_t file_size = 0;
@@ -78,15 +80,15 @@ char *get_proc_file(const char *filename)
}
while (!feof(f)) {
- size_t bytes = fread(file + file_size, 1, MAX_STRING_LEN, f);
+ size_t bytes = fread(file + file_size, 1, MAPS_FILESIZE, f);
file_size += bytes;
- if (bytes < MAX_STRING_LEN) {
+ if (bytes < MAPS_FILESIZE) {
break;
}
- file = realloc(file, buffer_size += MAX_STRING_LEN);
+ file = realloc(file, buffer_size += MAPS_FILESIZE);
}
file[file_size] = '\0';