|
Allocates a block of memory of requested size. Complexity is often constant-time, but might be O(C) where C is the number of Chunks in a FixedAllocator.
- Exception Safety Level
- Provides either strong-exception safety, or no-throw exception-safety level depending upon doThrow parameter. The reason it provides two levels of exception safety is because it is used by both the nothrow and throwing new operators. The underlying implementation will never throw of its own accord, but this can decide to throw if it does not allocate. The only exception it should emit is std::bad_alloc.
- Allocation Failure
- If it does not allocate, it will call TrimExcessMemory and attempt to allocate again, before it decides to throw or return NULL. Many allocators loop through several new_handler functions, and terminate if they can not allocate, but not this one. It only makes one attempt using its own implementation of the new_handler, and then returns NULL or throws so that the program can decide what to do at a higher level. (Side note: Even though the C++ Standard allows allocators and new_handlers to terminate if they fail, the Loki allocator does not do that since that policy is not polite to a host program.)
- Parameters:
-
| size | # of bytes needed for allocation. |
| doThrow | True if this should throw if unable to allocate, false if it should provide no-throw exception safety level. |
- Returns:
- NULL if nothing allocated and doThrow is false. Else the pointer to an available block of memory.
|