|
Why do you need a pointer?
e.g. if Key has a constructor Key(int) then instead of "return new Key(10)" with return type Key* you should be doing "return Key(10)" with return type Key. This way the compiler handles the allocations and frees for you.
The only time I ended up keeping track of pointers as you described is when generating strings for an object, and only that one time because I didn't think hard enough about a solution. You can always avoid these situations with better design.
|
|
|
|
|
Thanks Jheriko++,
The c++ library i use returns the allocated pointers and expect from the user of the library to delete these objects. The library has many such methods that returns newly allocated pointers so i cant change it.
every getSomethingX returns a new pointer
getSomething1->getSomething2->getSomething3->getSomething4....
for the flexibility reason i write code like the above otherwise i have to declare new pointer variable for every getSomethingX returned pointer so i can delete it later.
|
|
|
|
|
Its a shame that you are restricted by the library... you can at least avoid this trap in your own code though.
|
|
|
|
|
As a general rule, it's better to delete objects deliberately as soon as they are no longer needed. The mechanism you have described will continuously use more memory as the program runs. The longer it runs, the more memory will be consumed. You could eventually exhaust system resources, which is poor behavior .
I can see circumstances where your approach might be useful, however. Make sure that you mark your destructors virtual , and write a destructor for each class derived from your base object.
Software Zen: delete this;
|
|
|
|
|
thanks Gary,
Gary R. Wheeler wrote: As a general rule, it's better to delete objects deliberately as soon as they are no longer needed. The mechanism you have described will continuously use more memory as the program runs. The longer it runs, the more memory will be consumed. You could eventually exhaust system resources, which is poor behavior
Thats true i will declare pointer variables for newly returned pointers and delete them when they are no longer needed.
|
|
|
|
|
How do you change the working area of a non-primary screen?
AppBars effect the primary, but not the non-primary, from my experience.
TIA
|
|
|
|
|
mmm...
Screen? Or view?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Thanks MDV,
Screen, the .NET class that wraps an individual physical monitor.
It hold stuff like resolution, BPP, offset from primary screen, height, width, working height and width.
It is the workingarea that I am trying to modify. In the primary display, the change if made wirh the AppBar.
Thanks
RM
|
|
|
|
|
Then sorry, I dont have used .NET yet
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
I'm open to a non .NET solution, I was defining what the terms I used meant, as much as anything else.
|
|
|
|
|
I have created the window in MFC and I want that it should not move it. How can I do this?
Chetan
|
|
|
|
|
Have you looked into WM_WINDOWPOSCHANGING
From MSDN:
An application can prevent changes to the window by setting or clearing the appropriate bits in the flags member of the WINDOWPOS structure.
|
|
|
|
|
Hello All,
I am developing Server Application for RTMP Server, used for Flash.
I am sending to many messages on SOCKET . If it increase the number 750 packets then connection get close.
So anybody has idea about it?
Is it a problem of SOCKET
Thanks in advance
Regards,
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
I can only guess - either a bug or bad design.
It's up to you to deal with sending "to many messages".
Manish_mnp wrote: If it increase the number 750 packets then connection get close.
What does that mean? Socket connections don't close because of some kind
of packet increase.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You better watch it... you may begin to grow gills soon
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|
|
.
.
.
><::>
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Manish_mnp wrote: I am sending to many messages on SOCKET. If it increase the number 750 packets then connection get close.
Which error code do you get back?
Do you check receiver and sender side for errors, if yes check WSAGetLastError() or GetLastError() . Maybe your socket's send buffer is full and you have to wait until you can send more.
|
|
|
|
|
See what I found here, looks like the send buffer was full
|
|
|
|
|
Hi All,
In my project I want to get the string value set in text box. So I write
following code as
CEdit *pOpenEdit = (CEdit *) GetDlgItem(IDC_FOLDER_PATH);
if( NULL != pOpenEdit->GetSafeHwnd())
{
pOpenEdit->GetWindowText(buff,256);
}
In the above code I did not get handle of edit box. What is wrong in this code.
Please send me solution if anybody have.
Thanks
Om
|
|
|
|
|
What happens if you run this code?
CWnd *pwnd=GetDlgItem(IDC_FOLDER_PATH);
pwnd->GetWindowText(buff,256);
Or if you declare a variable for editbox
m_Edit.GetWindowText(buff,256);
or if you use of WM_GETTEXT message ?
|
|
|
|
|
When I run above code I get null handle. so the code on next line is not execute.
I use same code in other function of same class for Setting string value to editbox,the code is executed in that function. So why i did not get the handle od edit box in above code.
Plz reply me.
OM
|
|
|
|
|
Are you sure id of editbox is correct and what happens if you declare a variable for it did you can values of edit control.
|
|
|
|
|
Hi Hamid,
ID of Edit box is correct, because by using same ID i get the pointer for setting value to the window.
CEdit *pOpenEdit = (CEdit *) GetDlgItem(IDC_FOLDER_PATH);
if( NULL != pOpenEdit->GetSafeHwnd() )
{
if( strOpenPath != "" )
pOpenEdit->SetWindowText(strOpenPath);
}
This code is execute well but in following code i did not get the
handle.
CEdit *pOpenEdit = (CEdit *)GetDlgItem(IDC_FOLDER_PATH);
if( NULL != pOpenEdit->GetSafeHwnd() )
{
char buff[500];
pOpenEdit->GetWindowText(buff,256);
strOpenLocation = buff;
}
In this code I did not get handle so it is not entered in if block. Let me know what is wrong in this code.
Thanks in Advance
Om
|
|
|
|
|
I have a question why you didnt declare a variable for edit control instead handle to it?
|
|
|
|
|
/*
I'm not sure what your having trouble with. However, I am confused what your using the handle for? Do you realize that your trying to use a pointer before you've even checked that it is valid?
*/
void CTest712Dlg::ShowEditText()
{
if (::IsWindow(m_hWnd)) {
CEdit* pOpenEdit=(CEdit*)GetDlgItem(IDC_FOLDER_PATH);
if (pOpenEdit) {
CString sText("");
pOpenEdit->GetWindowText(sText);
TRACE("%s\n",sText);
}
}
}
void CTest712Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
ShowEditText();
}
|
|
|
|