Welcome, Guest. Please login or register.

Author Topic: double pointer indirection optimization dillema  (Read 2103 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show all replies
double pointer indirection optimization dillema
« on: March 10, 2005, 06:23:30 PM »
Arggg... I just spent 10 {bleep}ing minutes typing and it was gone!:pissed:

Anyway...

struct MajorArrayElement
 { LONG 2ndArrayOffset;
   LONG 2ndArrayNrElements;
   LONG *2ndArrayPointer;
 }*MajorArrayElementPtr;

I want to avoid having to use double indirection everytime I access an element of the 2ndArray:
*(MajorArrayElementPtr->2ndArrayPointer++)
or
MajorArrayPtr->2ndArrayPointer[nr.]

Both use MajorArrayPtr unnecessaryly.
I solved this by using another pointer that would be passed the adress of the 2ndArray's first element and then incremented(++) after each 2ndArray's element access.
But is there another way without using this? In assembler it's more easy but I want to keep my code portable and use the structre facilities of C.

Ahh, and DONT't tell me the compiler optimizes this and I shouldn't care 8-)
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show all replies
Re: double pointer indirection optimization dillema
« Reply #1 on: March 11, 2005, 06:26:18 PM »
"Storing an element's value in a temporary variable may prevent the compiler from optimizing references to MajorArrayElementPtr and its elements ..."

That's precisely the contrary of what I want to achieve. I want to know ways of optimizing it the mostly possible, not cripple the compiler's own optimization.
Basically I just though using a 3rd pointer was the best method to use to avoid using double indirection when a pointer is in some place pointed to by another pointer. I suppose some compilers optimize it when they see the number of accesses justify it but we don't have any control over it do we?
And if I use a 3rd pointer I'm actually making use of unecessary mem space, so more stack pushes and pulls and/or more address registers used.
I think I'm gonna let the compilers memory management handle it instead of writing obfuscated code. Someone must have already though about this.


\\"We made Amiga, they {bleep}ed it up\\"