Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #7658

Re: static struct and char arrays

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: static struct and char arrays
Date Sat, 09 Jul 2011 08:05:38 +1200
Lines 37
Message-ID <97p6a2F6tbU7@mid.individual.net> (permalink)
References <iv7dis$g2q$1@gregory.bnet.hr>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net MhGLJ7b2cRYnbIvhtmsYAg9u9PcZjve8I2hAOd/JpFVjd/v23p
Cancel-Lock sha1:sdlYFgArOhyWIou1fAfDnVCknkY=
User-Agent Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4
In-Reply-To <iv7dis$g2q$1@gregory.bnet.hr>
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:7658

Show key headers only | View raw


On 07/ 9/11 05:07 AM, A wrote:
> Hi,
>
> I want to use the advantage of having single allocation of a certain struct
> or array but keep it "local".
> For example - not to pollute my namespace I like to use a lot of "local"
> functions like this:
>
> void Function1()
> {
> struct TLocalFunction1
>      {
>      void operator()(int i)
>          {
>          char abc[] = {1,2,3,4,5};
>          }
>      } LocalFunction1
>
> // call "local" function
> LocalFunction(1);
> LocalFunction(2);
> // etc...
> }
>
> Now the problem is that I think this might be slowing down Function1 because
> TLocalFunction1 and char abc are constantly initializing from scratch.
>
> So, might I speed up if I prefix "struct TLocalFunction1" and "char abc"
> with the keyword "static" would that speed up the Function1 in terms of no
> more multiple allocations of TLocalFunction1 and char abc. Or is that
> compiler-dependent?

Probably. In this case there's nothing to initialise in the struct its 
self, but the char array may as well be declared static.

-- 
Ian Collins

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

static struct and char arrays "A" <a@a.a> - 2011-07-08 19:07 +0200
  Re: static struct and char arrays Ian Collins <ian-news@hotmail.com> - 2011-07-09 08:05 +1200
  Re: static struct and char arrays Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-07-09 00:53 +0200
    Re: static struct and char arrays "A" <a@a.a> - 2011-07-11 17:02 +0200

csiph-web