Click here to Skip to main content
13,354,132 members (58,983 online)

Visual Studio 2015 & .NET 4.6

 
GeneralRe: processor id Pin
vivek51118-Feb-13 0:48
membervivek51118-Feb-13 0:48 
GeneralRe: processor id Pin
Richard Deeming18-Feb-13 3:05
memberRichard Deeming18-Feb-13 3:05 
AnswerRe: processor id Pin
Mike Meinz18-Feb-13 6:23
memberMike Meinz18-Feb-13 6:23 
QuestionCrystal Report for Visual Studio 2010 Pin
source.compiler14-Feb-13 21:10
membersource.compiler14-Feb-13 21:10 
QuestionAdd a Class to a Windows App Pin
ASPnoob8-Feb-13 19:09
memberASPnoob8-Feb-13 19:09 
AnswerRe: Add a Class to a Windows App Pin
Richard MacCutchan8-Feb-13 23:55
mvpRichard MacCutchan8-Feb-13 23:55 
GeneralRe: Add a Class to a Windows App Pin
ASPnoob9-Feb-13 0:27
memberASPnoob9-Feb-13 0:27 
QuestionVirtual memory not released after my program ran out of memory ... Pin
Martial8-Feb-13 1:50
memberMartial8-Feb-13 1:50 
I've developped an application in C++ with Visual studio 10.
My program need to generate a huge quantity of small object (size = 12 Kb)in memory.
I want my program to manage the memory when the process run out of memory.
So I've implement a try/catch bloc to intercept this event. Then I free the memory and I tell the user that the operation is canceled.
But it seems in this case that the virtual memory is released not.

here's the code :
// AllocationErr.cpp : définit le point d'entrée pour l'application console.
//

#include "stdafx.h"
//#include <iostream.h> 
#include <vector> 
#include "AllocationErr.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

using namespace std;

void ReportMemory()
{
	MEMORYSTATUSEX statex;

	statex.dwLength = sizeof (statex);
	GlobalMemoryStatusEx (&statex);

	HANDLE heap = GetProcessHeap();
	SIZE_T size =  HeapCompact(heap, 0);

	BOOL validated = HeapValidate(heap, 0, NULL);

	TRACE("GlobalMemoryStatusEx:\n");
	TRACE(" + TotalVirtual : %0.1lf Mo\n", statex.ullTotalVirtual / (1024.0 * 1024.0));
	TRACE(" + AvailVirtual : %0.1lf Mo\n", statex.ullAvailVirtual / (1024.0 * 1024.0));
	TRACE(" + Process mem load : %0.1lf %%\n", (1.0 - (double) statex.ullAvailVirtual / (double) statex.ullTotalVirtual) * 100.0);
	TRACE(" + TotalPageFile : %0.1lf Mo\n", statex.ullTotalPageFile / (1024.0 * 1024.0));
	TRACE(" + AvailPageFile : %0.1lf Mo\n", statex.ullAvailPageFile / (1024.0 * 1024.0));
}

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    TRACE("Before allocation\n");
    ReportMemory();

    const unsigned int taille_bloc = 10* 1024, nb_blocs_max = (3U * 1024U * 1024U * 1024U / taille_bloc);
    int i = 0;

    char ** p = NULL;

    try
    {
        p = new char *[nb_blocs_max];

        memset(p, 0, nb_blocs_max * sizeof(char *));

        for(i = 0; i < nb_blocs_max; i++)
        {
            p[i] = new char[taille_bloc];
        }
    }
    catch (CMemoryException* e)
    {
        e->Delete();

        TRACE("After the program ran out of memory\n");
        ReportMemory();

        for(i = 0; i < nb_blocs_max; i++)
        {
            if(p[i])
            {
                delete [] p[i];
            }
        }

        delete [] p;
    }

    TRACE("After freeing memory\n");
    ReportMemory();

    char * t = NULL;
    try
    {
        const unsigned int taille_max = 30 * 1024 * 1024;
        t = new char[taille_max];
    }
    catch (CMemoryException* e)
    {
        TRACE("Memory allocation failed\n");
        e->Delete();

        if(t)
        {
            delete [] t;
        }
    }

    return 0;
}


Check the virtual available memory after the application free the memory ...
And check the next allocation of 30 Mb just after ...
Any Idea ?

Here's the result of the execution
Before allocation
GlobalMemoryStatusEx:
 + TotalVirtual : 2047.9 Mo
 + AvailVirtual : 2016.8 Mo
 + Process mem load : 1.5 %
 + TotalPageFile : 5198.6 Mo
 + AvailPageFile : 3172.9 Mo

After the program ran out of memory
GlobalMemoryStatusEx:
 + TotalVirtual : 2047.9 Mo
 + AvailVirtual : 4.5 Mo
 + Process mem load : 99.8 %
 + TotalPageFile : 5198.6 Mo
 + AvailPageFile : 1155.2 Mo

After freeing memory
GlobalMemoryStatusEx:
 + TotalVirtual : 2047.9 Mo
 + AvailVirtual : 5.7 Mo
 + Process mem load : 99.7 %
 + TotalPageFile : 5198.6 Mo
 + AvailPageFile : 3170.8 Mo


modified 8-Feb-13 6:58am.

QuestionCross page posting Pin
Tanaji.C30-Jan-13 1:38
memberTanaji.C30-Jan-13 1:38 
AnswerRe: Cross page posting Pin
Richard MacCutchan30-Jan-13 3:56
mvpRichard MacCutchan30-Jan-13 3:56 
AnswerRe: Cross page posting Pin
Pete O'Hanlon30-Jan-13 4:16
protectorPete O'Hanlon30-Jan-13 4:16 
GeneralRe: Cross page posting Pin
Tanaji.C30-Jan-13 18:10
memberTanaji.C30-Jan-13 18:10 
GeneralRe: Cross page posting Pin
Pete O'Hanlon30-Jan-13 19:50
protectorPete O'Hanlon30-Jan-13 19:50 
AnswerRe: Cross page posting Pin
Edo Tzumer3-Feb-13 0:09
memberEdo Tzumer3-Feb-13 0:09 
QuestionFiring event when creating instance of a class in C#.net Pin
Mir Hassan Shams Moosavi23-Jan-13 7:00
memberMir Hassan Shams Moosavi23-Jan-13 7:00 
AnswerRe: Firing event when creating instance of a class in C#.net Pin
Paulo Zemek23-Jan-13 7:09
memberPaulo Zemek23-Jan-13 7:09 
QuestionAssistant in the work of the Graduation Project Pin
alaa_2220-Jan-13 6:14
memberalaa_2220-Jan-13 6:14 
Questionosk to notepad Pin
srinivasankrishnaa16-Jan-13 5:08
membersrinivasankrishnaa16-Jan-13 5:08 
AnswerRe: osk to notepad Pin
Richard MacCutchan16-Jan-13 5:17
mvpRichard MacCutchan16-Jan-13 5:17 
Questionshortcut keys Pin
srinivasankrishnaa16-Jan-13 5:04
membersrinivasankrishnaa16-Jan-13 5:04 
AnswerRe: shortcut keys Pin
Mike Meinz23-Jan-13 4:28
memberMike Meinz23-Jan-13 4:28 
GeneralRe: shortcut keys Pin
srinivasankrishnaa16-Feb-13 4:20
membersrinivasankrishnaa16-Feb-13 4:20 
GeneralRe: shortcut keys Pin
Mike Meinz16-Feb-13 5:08
memberMike Meinz16-Feb-13 5:08 
QuestionC++/Cx syntax error Pin
Super Lloyd14-Jan-13 3:47
memberSuper Lloyd14-Jan-13 3:47 
NewsProblem solved Pin
Super Lloyd14-Jan-13 3:55
memberSuper Lloyd14-Jan-13 3:55 

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.


Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 22 Jan 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid