Google Interview Question
Software Engineer / DevelopersTeam: SRE
Country: India
Interview Type: Phone Interview
new operator will try to allocate memory first.
. if there is still enough space in current memory map, then a pointer to that area is returned.
. otherwise, break() system call will be called to allocate a new virtual memory area for the process. and the pointer is returned to the process
the while the new object got initialised, the first time access to the memory returned, it may cause a page fault if no physical page is allocated for the specific address, an exception that will enter kernel mode again. the kernel will allocate a new page for the process and back to user mode again. the data access as usual.
new operator allocates memory and (optionally) call object constructor.
- Anonymous April 02, 2012there are different memory allocators, e.g. simplest one is a memory pool
where data is allocated in chunks of fixed size, typically used by a firmware.
In general memory allocator is a quite complex to design because it should support
allocation of arbitrary length objects, take care of fragmentation, be reentrant for multi-threading apps and provide some debugging facilities..
i am not sure what this has to do with paging mechanism
which is part of virtual memory ?
as far as i know there is a hardware data structure, called TLB. Whenever
processor serves a memory request, hardware compares a part of the requested address
with entries in the TLB (loaded pages). If no match is found, an interrupt is thrown
and OS kernel is supposed to preload a missing page from external memory and then resume an interrupted instruction