Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to create and delete NodeData objects

    Posted 07/13/12 02:14 AM

    Originally posted by: Michael_D


    In a Concert 12.2 C++ application under Visual Studio 2010 and Win 7 64, when creating NodeData objects in the branch callback via

    
    pNodeData = 
    
    new (getEnv()) CMyNodeData(<arguments>);
    


    the following Visual Studio error message pops up after the branch callback has been left the second time and before it is entered the third time:
    'Windows has triggered a breakpoint in xxx.exe.

    This may be due to a corruption of the heap, which indicates a bug in xxx.exe or any of the DLLs it has loaded.

    This may also be due to the user pressing F12 while xxx.exe has focus.'
    When clicking this error message away by clicking on 'Continue', the following Visual Studio message pops up:

    'First-chance exception at 0x77b640f2 in xxx.exe: 0xC0000374: Ein Heap wurde beschädigt.

    Unhandled exception at 0x77b640f2 in xxx.exe: 0xC0000374: Ein Heap wurde beschädigt.' (Literally translated: 'A heap was damaged.')

    The exception occurs in ntdll.dll at the above address 0x77b640f2 in the function free(void*) (according to the Visual Studio disassembly window).

    As far as I can see, the issue seems to be that new (getEnv()) calls alloc(size_t sz) in iloenv.h, but when the node to which the NodeData pointer belongs is destructed, the standard C++ free(void*) is called, whereas presumably, the Ilog free(void* data, size_t sz) in iloenv.h should be called.

    When the second message is also clicked away by clicking on 'Continue', the problem gets solved as it should and even yields the optimal solution. Then, when solving further instances without terminating and re-starting the exe file, no further error messages pop up. This behaviour occurs in both the debug and the release version of the program.
    If, instead of the placement-new above,

    
    pNodeData = 
    
    new CMyNodeData(<arguments>);
    


    is used, everything works fine. (Then, the standard C++ operator new(size_t size) is called, which calls the standard C++ malloc function.) Everything, that is, except for the memory leaks that will occur, because I don't know where to put the corresponding delete.

    Questions:

    Which is the right way to create NodeData objects?

    (Where and how) can or should or must they be deleted by the user?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How to create and delete NodeData objects

    Posted 07/13/12 02:32 AM

    Originally posted by: SystemAdmin


    You are correct, you must not use placement-new to allocate user objects.
    They must be allocated using plain old "operator new".
    The user object at a node is deleted when the node is deleted. Upon deletion of a node, CPLEX automatically calls NodeData::~NodeData() so you should not need to care about destruction of the objects -- as long you implement an appropriate destructor.
    Note that nodes are not necessarily deleted when IloCplex::solve() returns. If the solve stopped due to a limit then CPLEX keeps the current tree in case you want to continue the solve. So the NodeData destructor should not assume that it is invoked in the context of a solve(), it may also be invoked during a call to IloCplex::end() (the destructor) and some other rare places.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: How to create and delete NodeData objects

    Posted 07/13/12 07:07 AM

    Originally posted by: Michael_D


    Thanks a lot!
    #CPLEXOptimizers
    #DecisionOptimization