|
A few ideas:
1. Since the line is executed millions of times, you may be able to speed it up with loop unrolling http://en.wikipedia.org/wiki/Loop_unrolling[^].
2. Every time you do pY[j], it requires a multiplication and an addition. If you're processing the array sequentially, it would be faster to start with a pointer to pY[0], then increment it to get the next array element.
If you show some more surrounding code, we may be able to see some other optimizations.
|
|
|
|
|
How to solve that problem in C language?
//struct BB; ?? Is there something similar as declaring class BB; in C++ ??
struct AA {
struct BB bb;
int a;
};
struct BB {
struct AA aa;
int b;
};
AA has BB member and BB has AA member.
chesnokov
|
|
|
|
|
As far as I know it will not work with C++ either. You have to use pointers to struct's. Like this
struct BB;
struct AA
{
struct BB* bb;
int a;
};
struct BB
{
struct AA aa;
int b;
};
This will work for C as well.
-Saurabh
|
|
|
|
|
No that also fails in compilation:
typedef struct _AA {
BB* bb; <--- C2016, C2061
int a;
} AA, *PAA;
typedef struct _BB {
AA* aa; <--- C2016, C2061
int b;
} BB, *PBB;
chesnokov
|
|
|
|
|
You forgot the forward declaration for struct _BB, try this.
struct BB;
typedef struct _AA
{
struct BB* bb;
int a;
} AA, *PAA;
typedef struct _BB
{
struct AA* aa;
int b;
} BB, *PBB;
-Saurabh
|
|
|
|
|
But you can not do that???
AA aa;
aa.a = 1;
aa.bb->b = 1; //error???
chesnokov
|
|
|
|
|
Should be aa->bb->b = 1;
-Saurabh
|
|
|
|
|
???
AA aa; //it is allocated on stack
aa.a = 1; //there is no error here
aa.bb->b = 1; //the error is here stating
error C2037: left of 'b' specifies undefined struct/union 'BB'
You will get the same error with
AA* aa;
aa&gt;bb->b = 1;
chesnokov
|
|
|
|
|
Oh Yes that one compiled
struct BB;
struct AA {
struct BB* bb;
int a;
};
struct BB {
struct AA* aa;
int b;
};
And that one also.
struct BB;
typedef struct _AA {
struct BB* bb;
int a;
} AA;
typedef struct _BB {
AA* aa;
int b;
} BB;
chesnokov
|
|
|
|
|
See this[^] thread.
Steve
|
|
|
|
|
I use forwarding references in C++ but I need them in C with structs and it does not work:
struct _BB;
typedef struct _AA {
BB* bb; //error
int a;
} AA, *PAA;
typedef struct _BB {
AA* aa; //error
int b;
} BB, *PBB;
chesnokov
|
|
|
|
|
Try something like this:
"A.h":
#ifndef __A_H__INCLUDED__
#define __A_H__INCLUDED__
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
typedef struct tagB B;
typedef struct tagA
{
B *pB;
} A;
#endif // !__A_H__INCLUDED__
"B.h":
#ifndef __B_H__INCLUDED__
#define __B_H__INCLUDED__
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
typedef struct tagA A;
typedef struct tagB
{
A *pA;
} B;
#endif // !__B_H__INCLUDED__
Steve
|
|
|
|
|
I'll see if it will solve the next problem!
That one compiles:
struct BB;
typedef struct _AA {
struct BB* bb;
int a;
} AA, *PAA;
typedef struct _BB {
struct AA* aa;
int b;
} BB, *PBB;
But you can not access BBs contents using AA object??
AA aa;
aa.a = 1;
aa.bb->b = 1; //error???? Ahhhh
chesnokov
|
|
|
|
|
Chesnokov Yuriy wrote: aa.bb->b = 1; //error???? Ahhhh
Should be as follows:
aa->bb->b = 1;
Steve
|
|
|
|
|
You have a lot of patience, man. My 5 .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
No way
AA aa;
aa->bb??? how can you access with -> object on stack not a pointer??
the glitch is
struct BB;
typedef struct _AA {
struct BB* bb;
int a;
} AA, *PAA;
typedef struct _BB {
struct AA* aa;
int b;
} BB, *PBB;
that one works but you can not access bbs constents from AA nor vice versa?
chesnokov
|
|
|
|
|
Yeah, you're right. So what's your problem exactly?
Steve
|
|
|
|
|
to compile and run that code:
struct BB;
typedef struct _AA {
struct BB* bb;
int a;
} AA, *PAA;
typedef struct _BB {
struct AA* aa;
int b;
} BB, *PBB;
main()
{
AA a;
BB b;
a.bb = &b;
b.aa = &a;
a.bb->b = 1;
b.aa->a = 3;
}
chesnokov
|
|
|
|
|
This works fine for me:
#include "stdafx.h"
struct BB;
struct AA
{
struct BB* bb;
int a;
};
struct BB
{
struct AA* aa;
int b;
};
void main()
{
struct AA a;
struct BB b;
a.bb = &b;
b.aa = &a;
a.bb->b = 1;
b.aa->a = 3;
}
Steve
|
|
|
|
|
You're having trouble with them being declared as pointers, and want them as real contained structs.
To borrow a phrase, "Imagine if you could do what you're asking".
AA would contain a BB which would contain an AA which would contain a BB which would contain an AA which would contain a BB which would contain an AA which would contain a BB which would contain an AA which would contain a BB which would contain an AA which would contain a BB which would contain an AA which would contain a BB which would contain an AA which would contain a BB...
I hope I'm getting the point across - I'm bored of typing. But your structure would end up infinitely large.
You can contain a *pointer* to your structures evil twin - a pointer only takes up a few bytes. But you need to give the pointer something to point to.
So:
struct BB;
struct AA
{
struct BB *bb;
int a;
};
struct BB
{
struct AA *aa;
int b;
};
main ()
{
AA a;
BB b;
a.bb->b = 1;
}
In the above example, C isn't psychic, so hasn't pointed A.bb at any BB structure. How can it? That's your job.
Try the below code.
AA a;
BB b;
a.bb = &b;
b.aa = &a;
a.bb->b = 1;
b.aa->a = 3;
Now your two structure can talk to each other to their heart's content.
I'd go back to your C book, and look up linked lists - it'll give you a light bulb moment about pointers.
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Iain Clarke wrote: I'd go back to your C book
If any.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Do not push to other limits I know to self refere them in future the glitch is it does not compile??
Try it yourself:
AA a;
BB b;
a.bb = &b;
b.aa = &a;
a.bb->b = 1; //error C2037
b.aa->a = 3; //error C2037
chesnokov
|
|
|
|
|
My apologies, I hadn't fully switched off my C++ brain.
try:
struct AA a;
struct BB b;
a.bb = &b;
b.aa = &a;
a.bb->b = 1;
b.aa->a = 3;
Though you could have worked that out for yourself...
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Iain Clarke wrote: Though you could have worked that out for yourself...
Another hint the C book was lost sometime.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Good day Guys,
Just would like to ask for help on this, how do I disable a tab in CTabCtrl?
I have a custom class extending CTabCtrl for some processing and also 3 Dialogs as Tabs.
On runtime, while processing on one tab, I would like to disable the other 3 tabs as not to mess
with the processing.
Thanks in advance
rbmarasigan2001
|
|
|
|