aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a>2008-10-17 10:00:31 +0000
committertradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a>2008-10-17 10:00:31 +0000
commit4438152282dcf471691a83dbc0eb31402955ad85 (patch)
tree3159dcfcd6e9bbf15d04ffaf7cc6b12a22b8249e
parentc553f14907bdb6096f75785349ee3c39101327e9 (diff)
preallocate buffer in IOUtil_GetAllParameters(), to prevent too many subsequent
reallocs which may cause unnecessary memory fragmentation git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOUtil/trunk@261 b32723a9-ab3a-4a60-88e2-2e5d99d7c17a
-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--)