[AGENT++] SNMP++/Agent++ on Windows (VC++) and the new operator

maom_onet at poczta.onet.pl maom_onet at poczta.onet.pl
Thu Feb 24 18:36:07 CET 2005


Dear friends,

I would like to warn SNMP++ and Agent++ Windows users who build applications with Visual C++ as it seems that by default, the new operator throws an std::bad_alloc exception (new C++ standard compliant approach) rather than returning null (the old-good (?) C++) when the heap is exhausted.

It is possible to manually enforce the old behavior with the placement form "new (std::nothrow)," although this may also be set at link time; in such a case, the behavior is defined by the link order of libraries (yes!).

In "The new and delete Operators" section of the C++ Library Reference one can find that there is a way to select the non-throwing new. For example, for my .NET wrapper library, in the Linker/Input/Additional Dependiencies section of the project settings, I added libcpmtd.lib just after libcmtd.lib (as the second linked library) and then verified that the new operator returns NULL. Before I added libcpmtd.lib, the operator threw exceptions on memory allocation problems.

Please refer to this manual section for details - it is even easier to enforce exceptions, although this breaks SNMP++ (as it is written in the old fashion).

Best regards,

Marek



More information about the AGENTPP mailing list