Bloomberg LP Interview Question
Software Engineer / DevelopersEffectively, if you want to avoid heap fragmentation. If suppose different size of memory is going to get allocate everytime, we might run out of big chunk of memory which might reduce the performance, so you can handle your own memory by creating fixed amount of memory for a particular object.
This need will be highly in the case of real time embedded applications.
void sample()
{
void* place = (void*) 0xFEEDBABE;
Fred* p = new(place) Fred(42, 42);
// ...
}
The above can be used for I/O operations or etc in embedded system,say, when the system is sure that a new Fred object get created only at the location 0xFEEDBABE and it has to interpret this class.
when information stored in 'front of block allocated' is greater than the block itself e.g. you are allocating characters using new. the info to locate this block / info to locate next free block/info to locate next allocated block will be much larger than the data itself.
- HAVOC May 03, 2010