Quantcast
Channel: EngineerZone: Message List
Viewing all articles
Browse latest Browse all 28044

Re: Re: Expectation when using new(heap_id) and heap_id not present in LDF

$
0
0

Hi Mike,

 

The issue here is that the call to new will throw a bad_alloc exception, which will take you to __lib_prog_term if it hasn't been caught.

 

So what you'd need to do in this case is either wrap the call to new in a try/catch handler:

 

void *newBaseAddress;

try {

  newBaseAddress = new (1) COFFEEPOT_STRUCTURE;

} catch (std::bad_alloc ba) {

  newBaseAddress = 0;

}

 

or call the nothrow version, which will return 0:

 

void *newBaseAddress = new (std::nothrow,1) COFFEEPOT_STRUCTURE;


Viewing all articles
Browse latest Browse all 28044

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>