EFI Interview Question for Software Engineer / Developers






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

#include <iostream>
#include <unistd.h>

using namespace std;

int main(void) {
	int* startMemoryAddress = (int*)sbrk(0);
	int* x = new int;
	int* endMemoryAddress = (int*)sbrk(0);
	cout << "heap allocated: " << (endMemoryAddress - startMemoryAddress)  << " bytes" << endl;
	delete x;
	return 0;
}


output: heap allocated: 33792 bytes

- m@}{ May 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Would you please explain what is sbrk(0)? And more importantly, what is the idea behind your code logic. Thanks.

- anonymous May 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

yes, i also could not understand your logic....can do this in c language.

I think the logic used by free(p)-->where p points to dynamically allocated memory.
who knows how much memory to free will be used,

- Anonymous May 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

brk() and sbrk() change the location of the program break, which
defines the end of the process's data segment (i.e., the program break
is the first location after the end of the uninitialized data segment).
Increasing the program break has the effect of allocating memory to the
process; decreasing the break deallocates memory.

Calling sbrk() with an increment of 0 can be used to find the current location of the program break.

- m@}{ May 31, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

As u mentioned brk() and sbrk() deals with the data segment area.Does this also applies to Heap Memory which is Dynamically Taken at run time??

- pnkj.nitrr May 31, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ur approach is simple n good, but have few questions

How to manage memory fragmentation?
How you manage if someone frees the memory in between

The best way to do this by intercepting malloc/free calls (in C).

- Ashutosh June 02, 2011 | Flag Reply


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