[openbeos] Re: Pointer or reference?

  • From: "anqe" <a_nqe@xxxxxxxxxxx>
  • To: <openbeos@xxxxxxxxxxxxx>
  • Date: Sun, 28 Mar 2004 21:47:03 +0100

> references seem a bit more efficient to me:  pointers require allocation
of a 4 byte space,
> initialization to the address to which they point and dereferencing takes
a small amount of extra
> time.  i personally like to USE pointers, but when it comes to the design
of an OS, shouldn't we
> incorporate everything we know?  if we are going to be in the media_kit
for example and are trying
> to push huge amounts of data around with little latency, perhaps using
references is different
> enough to improve the speed?

If anything const char* defenitions probably allow the compiler to generate
more efficient code and way. I've only had limited experience with writting
compilers and parsers, but in theory passing byref is telling the compiler
that your passing it something that could be constant and more importantly a
code time constant but that can't be guaranteed so the compiler has to
assume its a normal variable.

Either way the 4B is still gonna be transferred somewhere along the line,
via stack though the compiler nowadays might be passing it through in
fastcall.

That &string is gonna make the compiler generate an "lea esi, string" which
could possibly be avoided by using a constant pointer to the string. My
reasoning for this is that the compiler knows where it should be
initializing the variable and in some cases can make the assumption as to
where it is, allowing the lea to be avoided.

I could be off the mark, if so just ignore me (I try my best to ignore me)
but it seems that if worrying about 4B of memory is an issue then there are
probably other places to look for speed first. Condition hoisting and
appropriate usage of case and nested if structures would probably yield more
performance than chassing all calls.

bye

Other related posts: