Adobe Interview Question for Software Engineer / Developers






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

void *f = starting_memory_location;

void* myMalloc(int n)
{
//algorithm
(1)search for the first free node which has atlest n bytes in a circular linked list pointed by f(you have to change f, so that it circulates)(at start, theres only one node in the list with bytes as total available free space for dynamic allocation)
(2)when u find the node, if its size of free bytes equals to 'n', then mark it as used. else if its size is grater then 'n'(say 'm') then split it into 2 nodes, with firat node with size 'n'(marked as allocated) and another node with size (m-n) and marked as available
(3)if u go round 1 full rotation then return NULL

- mail2vcp@gmail.com September 29, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If malloc returns the pointer 'p' then p-1 should be the number are bytes allocated to the 'p'. We should also take care of that.

- Psycho October 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think in myMalloc function the parameter passed "int n" should not be bytes to be allocated.
Before allocation it should be properly aligned or padded.(based on the memory manager)

- sr.panigrahi October 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can use realloc...

- Abhi February 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can use realloc function ...

- Anonymous February 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void * myMalloc(int n)
{

/*f is pointing to free chunk of m byte */
void *p=f;
if(n>m) {
printf("Error: insufficient memory");
return NULL;
}
m=m-n;
f=f+n;
return p;

}

- Qamar December 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

just wondering f is lost here... but seems to be correct

- vijaymukilan July 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 0 vote

void* myMalloc(int n) {
*(int*)(f) = n// record the number of bytes allocated so that the runtime can free later
return f
}

- Anonymous July 27, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it should return f + 4 instead so that the length information doesn't get lost.

- Anonymous July 27, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

we can use realloc function ...

- abhi February 23, 2012 | Flag


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