You could break the data up into large chunks and then combine them. As with this example.
#include <stdio.h>
#include <tchar.h>
#include <mapidefs.h>
/// @def NELEMS(a)
///
/// @brief Computes number of elements of an array.
///
/// @param a An array.
#define NELEMS(a) (sizeof(a) / sizeof((a)[0]))
// Create a circular buffer (for Join())
static LPTSTR *ppBuffer = NULL;
/// @brief Concatenates two sub strings into a new string.
///
/// @param str1 A string
/// @param str2 Another string.
///
/// @returns A pointer to a temporarily allocated string.
LPTSTR Join(LPTSTR str1, LPTSTR str2)
{
register INT tmplen = 0;
register LPTSTR strtmp;
static INT StrCnt = 0;
if(NULL == ppBuffer) // initialize buffer
{
ppBuffer = (LPTSTR *) calloc(2, sizeof(LPTSTR));
}
tmplen = _tcslen(str1) + _tcslen(str2);
StrCnt = (StrCnt + 1) & 1;
if (ppBuffer[StrCnt])
free(ppBuffer[StrCnt]);
strtmp = (ppBuffer[StrCnt] = (LPTSTR)calloc(tmplen + 1, sizeof(TCHAR)));
_tcscat(strtmp, str1);
_tcscat(strtmp, str2);
return strtmp;
}
int main(int argc, char *argv[])
{
LPTSTR arrStrings[4];
arrStrings[0] = "Big string 1 + ";
arrStrings[1] = "Big string 2 + ";
arrStrings[2] = "Big string 3 + ";
arrStrings[3] = "Big string 4";
LPTSTR heapString = "";
for(int i = 0; i < NELEMS(arrStrings); i++)
{
heapString = Join(heapString,arrStrings[i]);
}
printf("%s\n",heapString);
return _getch();
}