[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Memory Allocation
- To: email@example.com
- Subject: Re: Memory Allocation
- From: Chris Purnell <firstname.lastname@example.org>
- Date: Wed, 1 May 2002 10:52:10 +0000
- Delivered-To: email@example.com
- Delivered-To: mailing list firstname.lastname@example.org
- Delivery-Date: Wed, 01 May 2002 06:52:24 -0400
- In-Reply-To: <3CD0AD71.66C5A6E4@airmail.net>; from email@example.com on Wed, May 01, 2002 at 10:07:29PM -0500
- Mailing-List: contact firstname.lastname@example.org; run by ezmlm
- References: <email@example.com> <02043021590601.00231@200191140086-dial-user-UOL> <3CD0AD71.66C5A6E4@airmail.net>
- Reply-To: firstname.lastname@example.org
- User-Agent: Mutt/1.2.5i
On Wed, May 01, 2002 at 10:07:29PM -0500, Steve Baker wrote:
> Igor Cabral Corr?a wrote:
> > I'm not making a game now, but I thinking something related with game
> > creation. Maybe you could aid me, please...
> > If I declare all variables of my program global, giving to the OS the task of
> > managing virtual/phisical memory for these variables, I have significant loss
> > of speed than when I manage the blocks of memory with malloc?
> It doesn't matter whether your variables are global, local or dynamically
> allocated onto the heap - Linux will manage them for you in *exactly* the
> same way.
> Like I said before - "Just don't worry about it."
> Otherwise, you might get a *tiny* speed advantage by using globals - but
> the ugliness that this induces into your code design isn't worth it.
For all but the most trivial of programs they'll be a speed penalty for
declaring all variables global. The instructions for globals tend to be
bigger and the storage space for local variables can be reused. So with
all globals you program will have a larger memory footprint with all that
implies. Also very short duration local variables can spend all their
lives in registers and have their storage optimised out completely.
You should define your variables with the appropriate scope so that
the compiler can manage them correctly.
Christopher John Purnell | I thought I'd found a reason to live
http://www.lost.org.uk/ | Just like before when I was a child
--------------------------| Only to find that dreams made of sand
What gods do you pray to? | Would just fall apart and slip through my hands