|
Now it is perfectly clear.
Thank you
Russell
|
|
|
|
|
I should have been more clear with the term "stack variable"...
I should have separated static and automatic variables:
int a[10000];
void SomeFunc()
{
...
}
void SomeFunc()
{
static int a[10000];
...
}
void SomeFunc()
{
int a[10000];
...
}
Objects created with "new" are generally on the runtime heap (unless you're
using a custom new operator and allocating memory some other way).
The stack is created at runtime when creating threads. The default size of the stack
for the primary thread of an executable is set by the linker, so I can't imagine
the compiler can tell you you've created too big of a stack variable. At runtime, however,
there will be a fault if you use too much stack space (stack overflow).
The stack is good for small, temporary objects. Allocating room on the stack is much faster
than allocating memory on the heap. Large objects should be created on the heap
regardless of their longevity. How big "small" and "large" objects are varies, depending
on stack size, nested function call depth, how many other objects are on the stack, etc.
Usually it's recommended that objects larger than a few KB should be dynamically allocated
on the heap, but again, that's arbitrary, and depends on the design of the application and the
system it's running on.
Hopefully a little more info,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank you ... It's mere then clear now.
This now remember me a question that is posted here days ago:
Why is preferred the way 2 to the (simpler) way 1?
way 1:
CDialog dlg;
way 2
CDialog *p;
p=new CDialog ;
This is giving to him another valid reason of this choose:
to let the stack be more free!
sizeof(CDialog) vs sizeof(CDialog*)
Russell
|
|
|
|
|
Hello all,
I have an iPhone and made a stupid mistake.
1) I got an iPhone and then did a 'sync' which put all my songs etc in the iTunes Music Library onto my iPhone
2) Then, thinking "Oh well, the songs are all on my iPhone now...to save some disk space I can erase my iTunes Music Library folders and ALL the files within!"
Duhhhh....
3) Having done that and regretting it, now iTunes won't let me put my songs back on my computer because it says, "The music library on this iPhone came from another computer."
Since I deleted ALL iTunes music files from my computer -- including the .xml etc control files, I can see where it might say this. However, it happens to not be the case.
Just to be clear...I do know I can copy iTunes Music Store-purchased stuff back to my computer, and that's great.
However, being the C++ and Windows programmer that I am, I am looking for a code hack to use the Windows API etc. to open the iPhone from my own code and copy files off of it. It's not immediately obvious if any of the standard Drive APIs will work, since it looks to the computer to be somewhat like a USB Mass Storage Device, although only somewhat....it has no drive letter when I plug the sync cable in.
However the "Scanner and Camera Wizard" from Windows always pops up when I plug the sync cable in and the iPhone shows up in My Computer with no drive letter, just as if it was a Digital Camera only...so I am wondering if there is anyway to crack the iPhone and get the songs off of it...
I believe there is a solution somewhere to this problem, since Tansee iPhone Transfer Software has obviously implemented some sort of working solution. However, it's not obvious that the aforementioned package is written in C++ and that's my favorite language to use...
Any suggestions would be greatly appreciated.
Sincerely Yours,
Brian Hart
Department of Physics and Astronomy
University of California, Irvine
|
|
|
|
|
Can anybody point me to any documentation / sample code on this???
My MSDN library does not know what CTabStrip is too!
Thanks a million
Vaclav
|
|
|
|
|
The MFC and CRT source code have never heard of it either.
What the heck is a CTabStrip?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It is the control containing just the tabs.
(Microsoft Forms 2.0 TabStrip.lnk in Registsered Active X controls in gallery _ VC6.0) )
I am hacking " visual framework "
( http://www.codeproject.com/dialog/visualfx.asp)
and I need to add a spinner control to move the tabs into focus when there are too many tabs in the tab client area.
I am having great time hacking this code and need to speed thigs up a little.
What I was going to do is make invisible tab control to gain acces to the spinner. But it is getting to complicated.
Vaclav
|
|
|
|
|
OK. With your help I managed to finish my project. One last thing to do.
How to build an exe file from my mfc project so it can run on any windows base computer?
|
|
|
|
|
|
|
Oh yeah, good One Bookmarked.
Thanks,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In my app, i need large float data, so i create a class for it.
but existing functions, such as sin(.), log(.) ..., are all use double, so I have to create similar functions to suit my large float numbers.
How to create my own sin(.), log(.) etc?
|
|
|
|
|
includeh10 wrote: so I have to create similar functions to suit my large float numbers.
http://www.netlib.org/cephes/[^] already exists.
But if you really want to write your own, pull the sources for GNU compilers standard math libraries, and extend them to long double.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
|
Hi people,
I m facing a problem with sockets.
My application connects to a device that has an IP and a port. If i switch on the device first and then my application i m able to establish consistent communication between them; however if i run the application first and then turn on the device it doesnt connect then.
P.S: I m using a Connect-button on the front-end to connect
Please help.
Button Connect function is as follows:
m_sConnectSocket1.Create();
m_sConnectSocket1.Connect(m_strIP1,m_iPort1);
|
|
|
|
|
You should check error codes...
m_sConnectSocket1.Create();
if (!m_sConnectSocket1.Connect(m_strIP1,m_iPort1))
{
int sockerrcode = m_sConnectSocket1.GetLastError();
if (sockerrcode == WSAEWOULDBLOCK)
{
}
else
{
}
}
...
void MySocketClass::OnConnect(int nErrorCode)
{
if (nErrorCode != 0)
{
return;
}
...
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I get error code 10035-WSAEWOULDBLOCK, that is when it connects but if i run the apllication first and then the device i get errorcode 10022 WSAEINVAL
If OnConnect() event is triggered shouldnt the error code be 10056?? Or, conversely, what error code(s) are/is possible if OnConnect() gets triggered??
By your code it seems a successful connection would produce an err-code of WOULDBLOCK.
Actually what i m doing in my new code is i keep trying to connect till the error code is 10056 or a timeout of 2 seconds, whichever is first. This i guess could be a wrong procedure. But it always works if i start the device first.
|
|
|
|
|
The possible error codes for Connect() are listed in the documentation for
CAsyncSocket::Connect() and also can be found in the Winsock docs:
connect() (Windows Sockets 2)[^]
Any time you use asynchronous sockets, an error of WSAEWOULDBLOCK
means the operation has NOT completed yet so no error info is available
at that time. To find out if the operation succeeded or not, you need
to get the results in whatever asynchronous completion method you're using.
In your case, that's in an overridden OnConnect() method.
yashveer wrote: Actually what i m doing in my new code is i keep trying to connect till the error code is 10056
That's not a proper way to check for a successful connection. Either there's an error or there's not.
You can find that out using the example code (or similar) that I posted previously.
And please use "WSAEISCONN" instead of "10056" when posting error codes.
I don't have them all memorized so I have to look them up. They'll make your code more
readable as well
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a problem. I am trying to catch some exception and I still haven't succeded. I tried with very simple example but still isn't working. Cakb someon help. Here is the code;
try
{
int a=5, b=0, c;
c = a/b;
}
catch (CException* e)
{
MessageBox("Division by zero exception!");
}
My program ends with error without executing the code in catch block.?????
|
|
|
|
|
try
{
int a=5, b=0, c;
c = a/b;
}
catch (...)
{
MessageBox("Division by zero exception!");
}
|
|
|
|
|
You can use of this code
try
{
int a=5, b=0, c;
if (b == 0)
throw int();
c = a/b;
}
catch (int)
{
MessageBox(_T("Division by zero exception!"));
}
|
|
|
|
|
See this[^] article on MSDN about exceptions. The first example illustrates handling divide-by-zero handling.
Software Zen: delete this;
|
|
|
|
|
Can I be able to convert VC++ builtin header files to DLL file.
As an experiment i tried in math.h but failed to create a dll.As build log said unable to register dll and dll was present no where.
And also how can i export my constants.Is that also possible?
Am I lacking a perfect picture of the whole thing DLL is doing?Help me please
|
|
|
|
|
You can't 'convert' header files into DLL's. A header file describes the contents of a DLL. A given header file may describe only part of a DLL. For example, math.h describes math-related functions in the C runtime library. The actual DLL in this case is MSVCRT.dll, which is usually installed in C:\Windows\System32.
You shouldn't need to do anything to create this DLL; it's installed as part of Windows, since so many Windows-supplied applications and components use it.
If you have general questions on creating and using DLL's, this[^] is an entire section of Code Project devoted to the subject.
Software Zen: delete this;
|
|
|
|
|
Can Anybody Tell me How to use picture Control.
I need to dynamically load the image on that picture Control.
Using Win32 Application
|
|
|
|