Pergunta de entrevista da empresa Adobe

Malloc is used to allocate memory. write a simplistic void * malloc(length) * free(void*) which work efficiently.

Resposta da entrevista

Sigiloso

14 de ago. de 2010

the interviewer essentially wants to hear about a simplistic O(1) way. my answer was to store the length of allocated memory in first 4 bytes and return the 4th byte whenever allocating. while deallocating a previously void * ; go back 4 bytes, read its length and free up length+4 bytes. this will make deallocation a constant time operation.

1