# Question about something defined in slob.c

• 04-18-2013
Xpl0ReRChR
Question about something defined in slob.c
Code:

`#define SLOB_UNITS(size) (((size) + SLOB_UNIT - 1)/SLOB_UNIT)`
Could someone explain to me what this does? I would be really greatful! :)
• 04-18-2013
spaghetticode
It defines a macro called "SLOB_UNITS" that calculates a certain value on the basis of a parameter "size" via the formula ((size) + SLOB_UNIT - 1) / SLOB_UNIT.

SLOB_UNIT seems to be another macro representing a constant value. Should also be defined somewhere in the file.
• 04-18-2013
Xpl0ReRChR
Thank you Dennis! SLOB_UNIT is defined as sizeof(slob_t), which is a struct describing a block.

I should have been more specific. What I meant to ask is, what is it that the formula represents?
• 04-18-2013
spaghetticode
Given that information:

Quote:

SLOB_UNIT is defined as sizeof(slob_t), which is a struct describing a block.
I'd suggest the formula determines how many slob_t elements the value of the parameter size contains. Say the struct slob_t has 2 kB. Now you pass your macro a size of, say, 16 kB:

Code:

`SLOB_UNITS(16)`
Go through the formula: (size (16) + SLOB_UNIT (2) - 1) / SLOB_UNIT (2))
16 + 2 - 1 / 2 = 8 (integer division!), which would be exactly the number of slob_ts in a size of 16.

The name of the macro makes sense that way, too.
• 04-18-2013
Xpl0ReRChR
It makes perfect sense, I should have tried using an example myself. Good point on the integer division!

Thank you for taking the time!