I'm reading some code of a model malloc (allocateMemory). I have posted a portion of the code, but I couldn't understand the purpose of size = (size_in_bytes + sizeof(int) - 1) / sizeof(int); (The last line in the posted code)
void initializeHeap(void) {
/* each chunk requires two signatures, one at the top and one
* at the bottom, so the available space inside a chunk is
* the number of elements in the chunk minus 2
*/
unsigned available_size = HEAP_SIZE - 2;
if (initialized) { return; }
/* write signatures at top and bottom of chunk */
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);