[En-Nut-Discussion] heap.c code optimization
Harald Kipp
harald.kipp at egnite.de
Sun Jan 16 11:18:56 CET 2005
Dusan,
Same code can be found in NutThreadCreate(). As a more
general solution (16-bit boundaries), we may combine it with
Tyou's H8 port, which uses a defined alignment:
if (0 != (size % MEM_ALIGNMENT)) {
size += MEM_ALIGNMENT;
size &= ~((SIZE)MEM_ALIGNMENT-1);
}
Thus we get
#if MEM_ALIGNMENT > 1
size = (size + MEM_ALIGNMENT - 1) & ~((size_t)(MEM_ALIGNMENT - 1));
#endif
or, alternatively
#if MEM_ALIGNMENT > 1
size += MEM_ALIGNMENT - (size & (MEM_ALIGNMENT - 1));
#endif
or create a macro
#define ALIGN_MEM(size)...
Harald
At 22:33 15.01.2005 +0100, you wrote:
>Hi guys,
>
>how do you like sitting following piece of code in your applications ?
>(os/heap.c:NutHeapAlloc)
>
>> while ((size & 0x03) != 0)
>> size++;
>
>What about to change it to
>
> size = (size + 3) & ~((size_t)0x03);
>
>I do not know exactly how it'll be compiled on various platforms but I
>feel it can be quicker.
>
>
>Dusan
More information about the En-Nut-Discussion
mailing list