Yahoo Interview Question for SDE1s


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
8
of 8 vote

The memory will be allocated according to the virtual memory available for the process & that can be higher (and is usually higher) than the RAM available on the system.

So, your program won't fail and the memory will be allocated. There is a thing called lazy allocation which means that the memory is actually not allocated until it's actually used.

- shadyabhi July 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

On 32 bit os, process can access virtual memory which is available upto 4GB and it is independent of RAM. So, process can allocate 600mb dynamic memory even ram is of 500mb.

- Raja July 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Agree. VM size is independent to physical memory. Notice that VM does depend on the swap size of disk. In the problem, if the swap size is less than 100mb, then the program can't actually run because the total physical storage is not even enough.

- waiging.lau July 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

people , who are saying it will succeed because of virtual memory, please write the program to allocate memory of size of RAM of your computer and try to run, it will fail.

- pspatel November 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if 500 mb is the ram size then definitely you might have set your virtual memory space as 4 times of that and in that case you might encounter page faults but if you are restricted only within this 500 mb of size what you can do is that in your program write your own memory handler function which will not allow you to do so. Or else you can refer external sorting methodology in this regard and please check how it gets solved there.

- S@iR@m July 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

malloc returns successfully only when it allocates the required amount of memory , so how is it possible that it allocates 600 mb at a time without having a RAM of suuficient size...

- P3A July 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@P3A, read my answer. "Lazy Allocation". That's something you're missing.

- shadyabhi July 24, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@shadyabhi... as you said, Lazy allocation means to allocate the memory when it is required, so the remaining part of the 600mb data will be stored in external storage. but Heap is used for malloc and the heap resides in physical memory, so how is it possible for malloc to return true as it will not have sufficient heap memory.

- Zzenith July 25, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Zzenith-heap is also a part of virtual address space of the process. Its not on physical memory.

- avi March 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

Are we sure on this?
Virtual memory surely allows to load bigger programs into memory, but the malloc allocates a new memory of the needed size frm the heap for the program, and it will not succeed
Static allocation wil be successful, but dynamic runtime allocation I believe will fail.

- Varun July 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

NO! Heap is large because process memory is large!!! It is from virtual memory!!!!!!!!!!!!!!!!!!!

- l337coder October 10, 2013 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 votes

Heap is taken from VM.

- Rishabh Pandita October 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Malloc will allocate the memory size of 600MB because malloc calls sbrk and brk for getting the free chunk of memory. sbrk allocates free chunk from system memory, also malloc deals with paged virtual system and as rightly pointed out using lazy memory allocation it can be done.

stackoverflow.com/questions/5716100/what-happens-in-the-kernel-during-malloc
stackoverflow.com/questions/6988487/what-does-brk-system-call-do

:brk calls heap which is in VM so so problem allocating till VM is available :)

- Rishabh Pandita October 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
-1
of 1 vote

u are weak technical
both come from the heaps !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

and the process don't know anything about physical /virtual it is all virtual!!!!!!!!!!!!!!!

- l337coder October 10, 2013 | Flag
Comment hidden because of low score. Click to expand.


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More