lilypond-devel
[Top][All Lists]
Advanced

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

Re: Reverse in std_vector.hh


From: Joe Neeman
Subject: Re: Reverse in std_vector.hh
Date: Fri, 08 Sep 2006 11:12:19 +1000

On Thu, 2006-09-07 at 21:58 +0200, Ruud van Silfhout wrote:
> it uses malloc to allocate memory for each item. This can also be done 
> using alloca, which allocates memory on the stack and, as a consequence, 
> does not have to be freed. but for alloca the same holds as for memrev, 
> it is not supported on all platforms so additional complexity has to be 
> added t to the configure scripting to determine whether alloca is 
> supported, so I left that out.

What about:

> 
> Bye,
> Ruud van Silfhout
> 
> additional memrev implementation:
> 
> void *memrev(void *block, size_t elsize, size_t elnum)
> {
//  void *pSwap = malloc(elsize);  // could have nbeen alloca(elsize)

    char pSwap[elsize]; // This is valid C++, right (it's certainly
                        // C99)?

>   char *pLeft = (char*)block;
>   char *pRight = (char*)block + (elnum-1)*elsize;
>   while (pLeft < pRight)
>     {
>       memcpy (pSwap,  pLeft,  elsize);
>       memcpy (pLeft,  pRight, elsize);
>       memcpy (pRight, pSwap,  elsize);
>       pLeft += elsize;
>       pRight -= elsize;
>     }
//  free(pSwap);  // not needed if alloca is used
>   return block;
> }
> 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]