|
yea .. F'd that up didn't i
David
|
|
|
|
|
char *charArray = new char[100];
char (*temp)[100]((char(*)[100])charArray); Then temp is a pointer to a char[100] array, so *temp is your array of 100 elements. The following should also work:
char (&temp)[100](*((char(*)[100])charArray)); In this case, temp is just an alias to the array, so you don't have to dereference it prior to accessing its members.
As for the reasons to do such a thing, they are many. One is if you have to create the array using a specialized memory allocation function, such as the case where you are using an external memory manager. For example, when coding for Matlab, you have to use mxAlloc to allocate ANY memory that will persist after your function is called. However, it may be more convenient in code to treat allocated memory as an array. As another example, suppose you create a template function that takes a 3D-array that you want to overload to take a 2D array. In this case, you would have to convert a TYPE[][] to a TYPE[1][][], which is a similar operation. For example,
template<size_t height, size_t width>
void doSomething(double (&darray)[height][width]) {
...
}
int main() {
const size_t height = 100;
const size_t width = 100;
double* memBlock2D = mxAlloc(height * width * sizeof(double));
double (&memArray2D)[height][width](*((double(*)[height][width])memBlock2D));
doSomething(memArray2D);
return 0;
} Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
modified on Tuesday, September 22, 2009 3:21 PM
|
|
|
|
|
Hi all,
I want to get cureent url from address bar of firefox.
Is there any snippet code to do this?
Thanx,
Jay
|
|
|
|
|
is there any way to get access to the details of the tasks show in the windows "task manager"? by c++.
|
|
|
|
|
Not with C++. Now if you were interested in some Windows API, there probably is. What did you have in mind?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
|
Hi
I just tried to call Sleep(1000) in a thread function
But when i tried to
Unit threadFun(LPVOID lparam)
{
while(1)
{
Sleep(1000); // When tried to give break point over here appliacation gets terminates
............
}
}
Can any one give me solution to this
Thanks
|
|
|
|
|
VVVimal wrote: Can any one give me solution to this
Remove the call to Sleep() . It's almost always unnecessary and usually indicates a design flaw.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
But i need a Sleep() function over there.
Because i need a function to be get called every 1000 milliseconds
|
|
|
|
|
VVVimal wrote: Because i need a function to be get called every 1000 milliseconds
Then use SetTimer(1000) .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Remember that Windows is not a real-time system, your function might or might not be called at every 1000 milliseconds, depending on what's happening on the OS.
This signature was proudly tested on animals.
|
|
|
|
|
VVVimal wrote: Unit threadFun(LPVOID lparam)
{
while(1)
{
Sleep(1000); // When tried to give break point over here appliacation gets terminates
............
}
}
I don't see why should the application "terminate" with this piece of code. (It might have probably helped us if you had given the remaining code within the thread function to see if anything is wrong)
With more than one thread running, may be the issue is somewhere else? Besides that, like David said, remove the unnecessary Sleep call and replace it with something that makes sense of some sort.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
does the application terminate or does it hang?
i would thing that statement would cause the app to hang... continuous loop with a defined wait time.. is that 1000 seconds or milliseconds it's library specific..??
David
|
|
|
|
|
David, you again replied to me instead of the OP. You should click reply on the specific message that you want to reply to.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
my questions are buried below..
David
|
|
|
|
|
I use Sleep() all the time in threaded code, there's no reason it should cause the termination in and of itself.
However, the thread code you show runs in the context of a larger program, notably the main thread which created the thread you show. What is that thread doing? If it exits, it will take the created thread down with it.
Make sure the main code is waiting for this thread to terminate before it does.
|
|
|
|
|
VVVimal wrote: When tried to give break point over here appliacation gets terminates
do you mean, it is getting terminated when you try to debug?
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
I just added
WatiForSingleObject(threadHandle,INFINITE)
now working fine. Can any one tell why does it so
|
|
|
|
|
My answer above told you exactly why WaitForSingleObject() solved the problem
However, the thread code you show runs in the context of a larger program, notably the main thread which created the thread you show. What is that thread doing? If it exits, it will take the created thread down with it.
|
|
|
|
|
Hi All
How can i read *.xlsx format?I am able to read *.xls format.Plz help me to read *.xlsx format.
|
|
|
|
|
MsmVc wrote: How can i read *.xlsx format?
Isn't it just an XML-type file? Regardless, just use Excel Automation and let Excel handle the details for you.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
thanks for reply but it is pure *.xlsx file and can i read *.xlsx file as a XML.
Plz help me
|
|
|
|
|
|
Hi,
I want to learn ATL. and I dont know any thing about ATL programming. Please send URLs for downloding any free PDF's, and please sujjest me the approach for learnig ATL.
Thnaks In Advance.
sampath-padamatinti
|
|
|
|
|
sampath-padamatinti wrote: I want to learn ATL
It is a demanding aim expecially when you miss the right 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]
|
|
|
|