|
Thank you Rajesh.
That is very kind of you.
«_Superman_»
|
|
|
|
|
Hi all,
I have 6 int values and a char buffer to pass another method. Something like this.
<br />
int MyClassOne::Method()<br />
{<br />
NemMwthod(1, 2, 3, 4, 5, 6, buffer);<br />
}<br />
<br />
int MyClassTwo::NewMethod(int a, int b, int c, int d, int e, int f, char buffer)<br />
{<br />
}<br />
Seems it's odd to me. So I do the following.
int MyClassOne::Method()<br />
{<br />
int* arr = new int[6];<br />
arr[0] = 1;<br />
arr[1] = 2;<br />
arr[2] = 3;<br />
arr[3] = 4;<br />
arr[4] = 5<br />
arr[5] = 6;<br />
<br />
NemMwthod(arr, buffer);<br />
delete[] arr;<br />
}<br />
<br />
int MyClassTwo::NewMethod(int ar[], char buffer)<br />
{<br />
}
I want to know what's best way to workaround is.
Thanks a lot
I appreciate your help all the time...
CodingLover
|
|
|
|
|
In my opinion, both methods are good.
I would prefer the first one, because it involves less copy operations.
As long as there is a fixed low number of integers to pass to the called procedure, the fist one is the best.
If the number of integers is variable, the second one is better.
An intermediate method would be:
int arr[6];
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
arr[3] = 4;
arr[4] = 5
arr[5] = 6;
NemMwthod(arr, buffer);
|
|
|
|
|
You can use
vector or CSimpleArray and pass that as a function parameter.
|
|
|
|
|
They are both legitimate, anyway IMHO the first one is more reliable, since the second one may crash your application if the caller passes an array having the wrong number of items (i.e. array size < 6).
Note that you may force the correct behaviour this way:
struct MyMethodArg
{
int arr[6];
char * buffer;
};
int MyClass::MyMethod(MyMethodArg arg)
{
}
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]
|
|
|
|
|
Thanks for all the comments, make sense.
But actually that method is call large number of times, say 50 times in one second. The way I workout is fine? I'm testing it, so far so good.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Which way?
If you use the array then you may choose to allocate it on the stack, instead of the heap, for instance
int a[]={1,2,3,4,5,6};
MyMethod(a,buf);
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]
|
|
|
|
|
Ya, but I've clear the head once pass the array.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: Ya, but I've clear the head once pass the array.
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]
|
|
|
|
|
Sorry sir, it should be heap.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: I want to know what's best way
Both are fine. Normally what I do is that if a function needs more than 5 parameters, I define a structure for it. It is just a standard that I follow. So its all up to you.
All parameters are passed on the stack and in Visual Studio the default stack space for a thread is 1 MB. So passing a structure will only use one location of the stack rather than 100 locations if you want to pass 100 parameters.
«_Superman_»
|
|
|
|
|
Actually those methods are in two different classes. Sorry about that, I'm asking it because I've no more knowledge about structures. Is that structures is possible here.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
You can define the structure in a header file and include the header file in both the class files.
«_Superman_»
|
|
|
|
|
A structure is what I would always do too. If there's a natural grouping to these items then having a struct defined for them is good practice anyway, including code readability. You just pass the struct, or a pointer to it, as suits. Nice and clean.
|
|
|
|
|
how to setting an edit box to prompt the user to enter hexadecimal numbeR?..
|
|
|
|
|
You can derived your class of Editbox and then overwrite WM_CHAR only for digital number for 0..9 and A..F.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
AFAIK, you have to write your own code to validate the entered number.
Luckily there are functions like strtol [^] (or _tcstol , if toxcct is nearby ) that may greatly help you.
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]
|
|
|
|
|
ouh..oke!!
let me try 1st..
thanks master!!..
|
|
|
|
|
As an alternative to what the other replies suggested you, you can still first search if somebody didn't already that for you. Check here[^] if you can find something that suits you.
It would amaze me if something like that is not available on CP...
But if it's not the case, that would be an idea for an article
|
|
|
|
|
NEED HELP!!
hii all..
anyone here knows how to convert the requested memory address to bus address???...
plss..im urgent!!
this is my email : hafizul_10422@yahoo.com
thanks all..
hv a great day!!
|
|
|
|
|
aswd wrote: anyone here knows how to convert the requested memory address to bus address???...
plss..im urgent!!
Nope. Anyway I may help you converting a memory address to a bus number , for instance the address 0x0E translates to tram no.14 , that travels from my home to Rome central railway station.
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]
|
|
|
|
|
thanks alot..
|
|
|
|
|
I may give you two suggestions:
- Read carefully the forum guidelines before posting.
- Go to (1) if you have any doubt.
For instance you should be more precise with your questions: What is the 'bus address' your talking about?
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]
|
|
|
|
|
oke..the bus address is the transaction address of the frontside bus(FSB)..so if a cpu want to do a transaction such as I/O transaction or Read/Write Data transaction, the cpu must request the bus address 1st for the cpu to do the transaction..so my problem is how to convert to requested memory address (cpu requests) to the bus address.
|
|
|
|
|
I suppose you may get better help posting in the Hardware & Devices forum [^].
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]
|
|
|
|