From 4438152282dcf471691a83dbc0eb31402955ad85 Mon Sep 17 00:00:00 2001 From: tradke Date: Fri, 17 Oct 2008 10:00:31 +0000 Subject: 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 --- src/CheckpointRecovery.c | 11 +++++++++-- 1 file 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--) -- cgit v1.2.3