Click here to Skip to main content
12,630,137 members (26,283 online)

Visual Studio 2015 & .NET 4.6

 
AnswerRe: Thanking Mike Meinz Pin
Richard MacCutchan20-Feb-13 6:35
mvpRichard MacCutchan20-Feb-13 6:35 
AnswerRe: Thanking Mike Meinz Pin
Sandeep Mewara20-Feb-13 7:27
mvpSandeep Mewara20-Feb-13 7:27 
Questionfind sentence with regular expression in VS Pin
Elham M18-Feb-13 22:25
memberElham M18-Feb-13 22:25 
AnswerRe: find sentence with regular expression in VS Pin
Pete O'Hanlon18-Feb-13 23:24
protectorPete O'Hanlon18-Feb-13 23:24 
Questionprocessor id Pin
srinivasankrishnaa16-Feb-13 4:38
membersrinivasankrishnaa16-Feb-13 4:38 
AnswerRe: processor id Pin
Mike Meinz16-Feb-13 5:22
memberMike Meinz16-Feb-13 5:22 
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 
QuestionAdding form close event Pin
andrew charles21-Dec-12 21:28
memberandrew charles21-Dec-12 21:28 
SuggestionRe: Adding form close event Pin
Richard MacCutchan22-Dec-12 0:07
mvpRichard MacCutchan22-Dec-12 0:07 
QuestionC++Cx / WinRT: Parameterized constructor (and operator overloading) for 'public value struct' Pin
Super Lloyd20-Dec-12 3:08
memberSuper Lloyd20-Dec-12 3:08 
AnswerRe: C++Cx / WinRT: Parameterized constructor (and operator overloading) for 'public value struct' Pin
Super Lloyd20-Dec-12 19:50
memberSuper Lloyd20-Dec-12 19:50 
Questionvc++ Pin
srinivasankrishnaa14-Dec-12 7:37
membersrinivasankrishnaa14-Dec-12 7:37 
AnswerRe: vc++ Pin
Super Lloyd14-Dec-12 21:11
memberSuper Lloyd14-Dec-12 21:11 
GeneralRe: vc++ Pin
srinivasankrishnaa17-Dec-12 5:22
membersrinivasankrishnaa17-Dec-12 5:22 
AnswerRe: vc++ Pin
ProgramFOX23-Dec-12 5:04
memberProgramFOX23-Dec-12 5:04 
AnswerRe: vc++ Pin
Edo Tzumer3-Feb-13 0:12
memberEdo Tzumer3-Feb-13 0:12 
QuestionWInRT component and event grief Pin
Super Lloyd11-Dec-12 5:51
memberSuper Lloyd11-Dec-12 5:51 
AnswerRe: WInRT component and event grief Pin
Pete O'Hanlon11-Dec-12 7:23
protectorPete O'Hanlon11-Dec-12 7:23 
GeneralRe: WInRT component and event grief Pin
Super Lloyd12-Dec-12 4:14
memberSuper Lloyd12-Dec-12 4:14 
GeneralRe: WInRT component and event grief Pin
Pete O'Hanlon12-Dec-12 4:19
protectorPete O'Hanlon12-Dec-12 4:19 
GeneralRe: WInRT component and event grief Pin
Super Lloyd12-Dec-12 12:25
memberSuper Lloyd12-Dec-12 12:25 
GeneralRe: WInRT component and event grief Pin
Pete O'Hanlon12-Dec-12 13:02
protectorPete O'Hanlon12-Dec-12 13:02 
GeneralRe: WInRT component and event grief Pin
Super Lloyd13-Dec-12 0:45
memberSuper Lloyd13-Dec-12 0:45 
GeneralRe: WInRT component and event grief Pin
Super Lloyd14-Dec-12 21:09
memberSuper Lloyd14-Dec-12 21:09 
GeneralRe: WInRT component and event grief Pin
Pete O'Hanlon14-Dec-12 23:50
protectorPete O'Hanlon14-Dec-12 23:50 
GeneralRe: WInRT component and event grief Pin
Super Lloyd15-Dec-12 2:57
memberSuper Lloyd15-Dec-12 2:57 

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 | Mobile
Web02 | 2.8.161205.3 | Last Updated 3 Dec 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid