Topic: Why prohibit allocator() throwing exceptions?


Author: "Peter M." <deja_pcm@my-deja.com>
Date: 1999/07/20
Raw View
I was wondering why the constructor for the std allocator is defined as
"allocator() throw()"?  Does this restriction also apply to the
constructors of user-defined allocators and does this imply that any
memory aquisition should not take place in an allocator's constructor?

Thanks,
- Peter


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Salters <msalters@lucent.com>
Date: 1999/07/22
Raw View
Peter M. wrote:
>
> I was wondering why the constructor for the std allocator is defined as
> "allocator() throw()"?  Does this restriction also apply to the
> constructors of user-defined allocators and does this imply that any
> memory aquisition should not take place in an allocator's constructor?
>
> Thanks,
> - Peter

(only answering your last question:)

You can allocate memory there, but you'd need to catch the execption
thrown by new - if you use that - or handle the OS specific error
return if you're allocating OS-specific memory (e.g. shared memory).

The idea is that memory allocation problems are better reported at
a time the program is able to handle them (better).

Michiel Salters


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]