aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CheckpointRecovery.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/CheckpointRecovery.c b/src/CheckpointRecovery.c
index 5d79672..838891d 100644
--- a/src/CheckpointRecovery.c
+++ b/src/CheckpointRecovery.c
@@ -786,9 +786,16 @@ char *IOUtil_GetAllParameters (const cGH *GH, int all)
/* avoid compiler warning about unused parameter */
GH = GH;
- retval = NULL;
+ /* preallocate buffer for parameters, to prevent too many subsequent reallocs
+ (causing unnecessary memory fragmentation) */
+ max_len = 1024*1024;
+ retval = malloc(max_len);
+ if (! retval)
+ {
+ CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Failed to allocate buffer of %d bytes", max_len);
+ }
current_len = 0;
- max_len = 1;
/* loop over all thorns */
for (i = CCTK_NumCompiledThorns () - 1; i >= 0; i--)