lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> > Moreover, the only portable way to check multiplication overflow is by
> > doing a division, which is not very efficient.
> I express no opinion regarding the addition of a new allocation function.
> But the following is a routine I wrote for use in some of my libraries,
> usually for checking overflow when allocating memory. It's portable C (well,
> see inline comment regarding lobits on how to make it portable) and it was
> about 5x faster than using division on the Intel Core chip I tested it on. I
> believe the treatment of signed integers would be nearly identical and
> equally portable C code, although I can't speak to the additional cost of
> handling signedness.

I stand corrected on that point, thanks for the code. Anyway, that code
is still more expensive than (nelem > MAX_SIZET/size), when 'size' is
a constant. (I have some doubts about signed integers being nearly
identical, but that is besides the point here, where everything is
unsigned). And I think my other points (mainly about overflow being
better handled in an "hollistic" way :-) are still valid.

-- Roberto