Microsoft Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
in the heap, we have a hash table which includes the size of this new address space. So when we free this space, we will know how many space do we need to free.
Address malloc(Byte size){
Address entryAddr = null;
try{
entryAddr = getSizeMemFromHeap(size);
}catch(Exception e){
print(e.getMessage);
System.exit(e.errorCode);
}
HashTable ht = getHashTableEntry();
ht.add(entryAddr,size);
claimAddrNotAvaialble(addr,size);
return entryAddr;
}
void free(Address addr){
if(addr == null){
return;
}
HashTable ht = getHashTableEntry();
Byte size = ht.get(addr);
//tell OS that from addr to addr+size, this address space is available
//we don't need to delete them, just claim it
claimAddrAvaialble(addr,size);
}
hi hprem991, can you please answer or give the link to old answer ?
- hint February 14, 2013