I am reading some malloc model code (allocateMemory). I posted a piece of code, but I could not understand the purpose of size = (size_in_bytes + sizeof (int) - 1) / sizeof (int); (Last line in published code)
void initializeHeap(void) {
unsigned available_size = HEAP_SIZE - 2;
if (initialized) { return; }
memory_pool[0] = available_size;
memory_pool[HEAP_SIZE - 1] = available_size;
initialized = true;
}
void* allocateMemory(unsigned size_in_bytes) {
int size;
unsigned chunk;
int chunk_size;
initializeHeap();
size = (size_in_bytes + sizeof(int) - 1) / sizeof(int);
source
share