On Apr 15, 2010, at 15:34 , Denys Rtveliashvili wrote:
As for the performance of "alloca", I though it would be faster than "malloc". However, in a simple test I have just written it is actually slower. The test allocates 16-bytes arrays and immediately de-allocates them. This operation is repeated 1000000000 times. On my computer the C program takes 27 seconds to complete while Haskell version takes about 41.
Your C program is doing nothing but adjusting linked lists after the first time the block is allocated. free() puts the block at the head of a linked list of free blocks, and malloc() will find it there, unlink and return it.