a = b or memset/cpy?
- From: nroberts <roberts.noah@xxxxxxxxx>
- Date: Tue, 7 Feb 2012 09:02:06 -0800 (PST)
memset and memcpy are turning up in profiles a lot. I'd like to speed
things up a bit.
Sometimes it is clear that using = to initialize a local would be
better than memset. I might not gain anything, but at least there's a
chance.
However, can I gain performance improvements when zeroing out say some
global element in an array like so:
typedef struct x { int var0; char var1[20]; } X;
X gX[30];
void f(int slot)
{
X init = {0};
gX[slot] = init;
...
}
vs.
void f(int slot)
{
memset(&gX[slot], 0, sizeof(X));
...
}
Normally I wouldn't look for a micro-optimization like this but I'm
kind of stuck with the parameters I'm given.
.
- Follow-Ups:
- Re: a = b or memset/cpy?
- From: Joe keane
- Re: a = b or memset/cpy?
- From: Jorgen Grahn
- Re: a = b or memset/cpy?
- From: Eric Sosman
- Re: a = b or memset/cpy?
- From: Shao Miller
- Re: a = b or memset/cpy?
- From: Scott Fluhrer
- Re: a = b or memset/cpy?
- From: Jens Gustedt
- Re: a = b or memset/cpy?
- Prev by Date: Re: Optimisation questions
- Next by Date: Re: what is the right value about a = a++;
- Previous by thread: test message
- Next by thread: Re: a = b or memset/cpy?
- Index(es):
Relevant Pages
|