Hi,

currently using dynamic arrays (which implicitly uses alloca()) is used by default with heap allocation via new/delete as fallback if the compiler does not support
dynamic arrays.

I guess that is good enough (as a GNU maintainer I feel like there there should be
a small performance penalty for not using gcc :-) ).

/// Jürgen


On 04/06/2014 05:04 AM, Blake McBride wrote:
With 20+ years C experience, IMO using alloca() as a way of allocating computed sized arrays is good. There are other speed advantages of using alloca too. Like many C library calls, alloca only works because of the fact that it is specifically designed to work with a specific tool chain. That's not bad, many other calls are too. If you use a different tool chain (i.e. GNU, Solaris, Intel, etc.) each will come with a fully functional alloca. Once you code it, it'll work fine. The risk of blowing out the stack is always there, and the risk of clobbering the stack by going past the end of the array is always there in any C function.

If you don't use alloca, you'd have to either malloc the space, provide a fixed size, or pass in a buffer. Alloca is much more efficient than malloc. Using a fixed array is space and time wasteful.

Just an opinion.

Blake



On Sat, Apr 5, 2014 at 8:26 AM, Juergen Sauermann <juergen.sauerm...@t-online.de <mailto:juergen.sauerm...@t-online.de>> wrote:

    Hi,

    I hope the Solaris issues are fixed now (SVN 187). Please complain
    if not.

    I decided against alloca() because the description on its man page
    suggested more problems than advantages.

    /// Jürgen


    On 04/03/2014 02:55 PM, Elias Mårtenson wrote:

    It would, but OpenMP is not supported on it. Also, the Solaris
    Studio compiler tends to generate better code.

    Also, alloca() (as opposed to malloc() which allocates memory on
    the heap) behaves exactly the same as dynamically advocated
    arrays. They both allocate space on the stack. In fact, I believe
    GCC generates exactly the same code for both cases. They both
    essentially translates to an add instruction of the stack pointer.

    Regards,
    Elias

    On 3 Apr 2014 20:33, "Juergen Sauermann"
    <juergen.sauerm...@t-online.de
    <mailto:juergen.sauerm...@t-online.de>> wrote:

        Hi Elias,

        I will look into this, but some have performance impacts
        (dynamic arrays).
        Wouldn't it make sense to install gcc on Solaris?

        /// Jürgen



        On 04/02/2014 12:46 PM, Elias Mårtenson wrote:
        Also, if you want to try out the Solaris compiler, it's
        available for free for Linux as well:
        
http://www.oracle.com/technetwork/server-storage/solarisstudio/beta-1947596.html


        To enable OpenMP you need to compile with
        *-xopenmp=parallel* and set some environment variables as
        described here:
        http://docs.oracle.com/cd/E18659_01/html/821-1381/aewcb.html#gkcrd

        Regards,
        Elias


        On 2 April 2014 18:39, Elias Mårtenson <loke...@gmail.com
        <mailto:loke...@gmail.com>> wrote:

            Oh, and there are a few more dynamically sized arrays:

              * phrase_gen.cc:115 and 222

            Regards,
            Elias


            On 2 April 2014 18:34, Elias Mårtenson
            <loke...@gmail.com <mailto:loke...@gmail.com>> wrote:

                On 2 April 2014 18:32, Elias Mårtenson
                <loke...@gmail.com <mailto:loke...@gmail.com>> wrote:

                    Declaring an array with a size computed at
                    runtime is not actually allowed (it's supported
                    in modern C, and also supported in C++ as an
                    extension).


                What I meant was that it's supported in /GCC/ as an
                extension, not C++.

                Regards,
                Elias







Reply via email to