Click here to Skip to main content
15,895,799 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: modulus operator Pin
Naveen12-Jul-06 17:41
Naveen12-Jul-06 17:41 
GeneralRe: modulus operator Pin
thathvamsi12-Jul-06 18:06
thathvamsi12-Jul-06 18:06 
GeneralRe: modulus operator Pin
Naveen12-Jul-06 18:17
Naveen12-Jul-06 18:17 
Questionhelp useing Microsoft HTML Object Library in visual c++ 6 Pin
method00712-Jul-06 12:14
method00712-Jul-06 12:14 
AnswerRe: help useing Microsoft HTML Object Library in visual c++ 6 Pin
nguyenvhn12-Jul-06 17:32
nguyenvhn12-Jul-06 17:32 
GeneralRe: help useing Microsoft HTML Object Library in visual c++ 6 Pin
method00712-Jul-06 17:47
method00712-Jul-06 17:47 
QuestionC++ memory question Pin
mdexch12-Jul-06 11:59
mdexch12-Jul-06 11:59 
AnswerRe: C++ memory question [modified] Pin
earl12-Jul-06 13:11
earl12-Jul-06 13:11 
I reformatted your code to make it easier for me to read, particularly since C++ (which you are using) provides references.

wchar_t *pwcTest = L"Test";
int g_I=1000;

void AllocateMem(wchar_t**& pwcArray)
{
    pwcArray = new wchar_t*[g_I+1];
    
	ZeroMemory(pwcArray, sizeof(wchar_t*) * (g_I+1) );

    for(int i=0; i<g_I; i++) {
        pwcArray[i] = new wchar_t[ wcslen(pwcTest) + 1 ];    
        wcscpy(pwcArray[i], pwcTest);
    }
    pwcArray[ g_I ] = NULL;
}

void FreeArray(wchar_t **pwcDC)
{
    if(pwcDC != NULL) {
        for(int i=0; pwcDC[i] != NULL; i++)
            delete [] pwcDC[i];
        delete [] pwcDC;
    }
}

int main( int argc, char *argv[ ])
{
    char s[2];

    printf("main:\n");
    fscanf(stdin, "%s", s);
    // Mem Usage (in the Windows Task Manager): 632K

    wchar_t** pwcArray = NULL;

	int i;
    for (i=0; i<1000; i++) {
		if (i%100 == 0)
			fprintf(stdout, "%d\n", i);

        AllocateMem(pwcArray);
        FreeArray(pwcArray);
    }
    printf("main: %d\n", i);
    fscanf(stdin, "%s", s);
    // Mem Usage: 688K (g_I=1000)
    // Mem Usage: 908K (g_I=10000)

    return 0;
}


I don't believe my version leaks memory, though I only spent a couple minutes on this. The CRT will ask windows for memory then hold on to it for future requests, even if from your perspective you haven't currently allocated it -- or at least this is my understanding.

earl

PS: VS2005: beginning 960K, end 1000K, regardless i = {1000,10000,50000}

-- modified at 19:28 Wednesday 12th July, 2006
GeneralRe: C++ memory question Pin
mdexch14-Jul-06 7:58
mdexch14-Jul-06 7:58 
AnswerRe: C++ memory question Pin
Joe Woodbury12-Jul-06 14:11
professionalJoe Woodbury12-Jul-06 14:11 
GeneralRe: C++ memory question Pin
kanduripavan12-Jul-06 20:46
kanduripavan12-Jul-06 20:46 
GeneralRe: C++ memory question Pin
Joe Woodbury13-Jul-06 0:11
professionalJoe Woodbury13-Jul-06 0:11 
Questionsscanf will only put value in first variable Pin
Evilpixie12-Jul-06 11:32
Evilpixie12-Jul-06 11:32 
AnswerRe: sscanf will only put value in first variable [modified] Pin
earl12-Jul-06 12:46
earl12-Jul-06 12:46 
GeneralRe: sscanf will only put value in first variable Pin
Evilpixie12-Jul-06 13:11
Evilpixie12-Jul-06 13:11 
GeneralRe: sscanf will only put value in first variable Pin
earl12-Jul-06 13:14
earl12-Jul-06 13:14 
GeneralRe: sscanf will only put value in first variable Pin
Evilpixie12-Jul-06 13:17
Evilpixie12-Jul-06 13:17 
AnswerRe: sscanf will only put value in first variable Pin
Stephen Hewitt12-Jul-06 14:08
Stephen Hewitt12-Jul-06 14:08 
QuestionColor management in CDC Pin
TchouTchou Project12-Jul-06 11:23
TchouTchou Project12-Jul-06 11:23 
AnswerRe: Color management in CDC Pin
A_Fa12-Jul-06 20:09
A_Fa12-Jul-06 20:09 
QuestionHow can I convert to TIFF file format? [modified] Pin
Cris12-Jul-06 9:47
Cris12-Jul-06 9:47 
AnswerRe: How can I convert to TIFF file format? Pin
Christian Graus12-Jul-06 9:55
protectorChristian Graus12-Jul-06 9:55 
AnswerRe: How can I convert to TIFF file format? Pin
Joe Woodbury12-Jul-06 10:28
professionalJoe Woodbury12-Jul-06 10:28 
GeneralRe: How can I convert to TIFF file format? Pin
Cris13-Jul-06 2:00
Cris13-Jul-06 2:00 
GeneralRe: How can I convert to TIFF file format? Pin
Joe Woodbury13-Jul-06 8:19
professionalJoe Woodbury13-Jul-06 8:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.