|
use auto_ptr...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Don't overabuse auto_ptr: you don't need to wrap every pointer into a smart pointer when it is not required.
|
|
|
|
|
There is probably something wrong in your destructor. Use your debugger to see exactly what is happening (check if the pointers are valid and so on).
|
|
|
|
|
The memory leak control implemented on the CRT overloads the new and delete operators to add some extra memory to contain some signatures that are tracked by a global data structure.
At end, is something is wrong between this structure and the related allocated memory a warning is reported.
In your case your obj pointer is also a global data. But since the initialization order of global data is not predictable (in the sense that it depends on the order the linker links the modules) probably your "new " call happens before the tracking structure is properly initialized (hence, it isn't tracked).
But the delete is. Hence the misleading and the resulting report.
Try this:
class myhandle
{
myclass* p;
public:
myhandle() :p(new myclass) {}
~myhandle() { delete p; }
myclass* operator->() const { return p; }
};
myhandle thehandle;
INT WINAPI WinMain( ....)
{
myhandle->do_something_with_myclass(...)
return 0;
}
Now allocation and deallocation are wrapped in ctor / dtor.
When thehandle is created the compiler will place an "atexit" to invoke the destructor.
Since the order of destruction is the inverse of the order of construction, you're so granted that either both new and delete are tracked or none of them is. Both case are coherent.
<edit>
I see just now ThatsAlok writing "use auto_ptr".
In fact std::auto_ptr behave just like myhandle in respect to construction / destruction.
</edit>
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Your program is not causing any assertion, but the following is. May be you are doing something like this -
class myclass
{
public:
char Ary[200];
char *p;
myclass()
{
p = new char[1000];
}
~myclass()
{
delete []p;
}
};
myclass *obj = new myclass();
myclass *obj2 = new myclass();
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
delete obj2; //not getting error here.
obj = obj2;
delete obj; //getting error here.
return 0;
}
|
|
|
|
|
you didn't take in account what i told you yesterday.
Fix your signature immediately. the html you use in it is not well formatted[^]not well formatted, thus a break in the pages' style.
if you use too much characters in the sense that CP don't allow much, then reduce your signature.
|
|
|
|
|
Ok I got it. there were too many charcters. and so it was happening. I have remooved the charcters. And I think now its correct
|
|
|
|
|
GauranG33 wrote: Ok I got it. there were too many charcters. and so it was happening. I have remooved the charcters. And I think now its correct
actually, it's a bit better, but not perfect.
here is your sig :
<b>G</b>auran<b>G</b><sup><font color=red>33</sup>
you're not closing the <font> tag...
|
|
|
|
|
I think this will be right
GauranG33
|
|
|
|
|
|
I notified him twice of the very same thing. He's convinced nothing is wrong.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: He's convinced nothing is wrong
seems that he finally figured out he had a problem 'cause he's fixed it now
|
|
|
|
|
Hi,
I am getting the following error while building the code in Debug code:
error PRJ0019: A tool returned an error code from "Performing Custom Build Step
Please help regarding the following error.
Regards
|
|
|
|
|
from MSDN:
An error level was nonzero for a custom build step or build event.
It seems that your custom build step failed. Plz check the steps written in it.
|
|
|
|
|
The message i am getting is p[osted here.Please help what should i do to get rid of this error:
>Deleting intermediate and output files for project 'AudioCap', configuration 'Debug|Win32'
1>Performing Custom Build Step
1>MC: -u switch must be used with Unicode message file!
1>Project : error PRJ0019: A tool returned an error code from "Performing Custom Build Step"
1>Build log was saved at "file://d:\voice editor sw\VRS\AudioCap\Debug\BuildLog.htm"
1>AudioCap - 1 error(s), 0 warning(s)
Regards,
|
|
|
|
|
MC: -u switch must be used with Unicode message file!
May be your project settings are ANSI, and you are using switch -u which is for unicode files. Use -a in place of -u.
Or paste the "Custom build step" steps. Also tell about your project settings, ANSI or UNICODE ?
|
|
|
|
|
hits07 wrote: 1>MC: -u switch must be used with Unicode message file!
How clear do you want it? The Message Compiler (MC) is needing the -u switch. See here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I want to open the dialog box for browse button in order to select single or multiple files. I am using MFC.
how to do it.
Thanks In aadvance.
Dhiraj Kumar Saini
|
|
|
|
|
The class for showing the dialog is CFileDialog .
You can use the following sample code -
char szFilters [] = "Text Files (*.text)|*.txt|";
CFileDialog FileDialog (TRUE, "txt", "", OFN_FILEMUSTEXIST, szFilters, this);
CString FileName;
if (FileDialog.DoModal () == IDOK)
{
FileName = FileDialog.GetPathName ();
}
|
|
|
|
|
Hi,
I have list control whose property is set to
"List1",IDC_CmdResp,"SysListView32",LVS_REPORT |
WS_BORDER | WS_TABSTOP,293,37,146,214,
WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_RIGHT |
WS_EX_STATICEDGE
Am displaying the data read from the serial port in the list control but there is lot of filckering.Below is the code to display the data in list control.Is there any thing am missing in the code.Why there is flickering?More flickering starts when i start deleting the data.If i don't delete i get assert error that maybe due to memory overflow of the list control.Plz help me out.
void CNgpptDialog::ReadSerialData(CString sIn)
{
CString pressure_data;
ptrCmdResp->SetRedraw(false);
pressure_data=sIn;
int counter = ptrCmdResp->GetItemCount();
ptrCmdResp->InsertItem(counter, "");// to insert a row
ptrCmdResp->SetItemText(counter, 0, pressure_data);// column0
ptrCmdResp->EnsureVisible(counter, FALSE); // Scrolls downwords.
if(counter > 150)// I start deleting first data when the number of items in the list control is > 150
{
ptrCmdResp->DeleteItem(0);
}
ptrCmdResp->SetRedraw(true);
int nIndex = ptrCmdResp->GetItemCount();
ptrCmdResp->RedrawItems(nIndex,nIndex);
}
}
Thanks in advance
|
|
|
|
|
With one post is enough... at least you could change your text and explain yourself in another way. Maybe is not clear what you mind (i.e. I don't know the word flickering)
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
|
|
|
|
|
K Got it.
The actual issue is
When i place the data in List Ctrl the data is unsteady.As am placing data continuously(120 samples/ sec)and i have run the s/w for many days continuously, i need to delete the data in List Ctrl otherwise buffer of the List Ctrl will overflow.After displaying 150 samples in Ctrllist am starting to delete at this moment data is unsteady.
Thanks
|
|
|
|
|
Well, I reset tmy ListCttrlView everytime the OnDraw is called to empty all datas and then I write the newest values.
void CMyTabView::OnDraw(CDC* pDC)
{ if (m_bJustOpened)
InitializeView ();
if (m_bListRedraw)
DrawViewElements ();
return;
}
In initialize views I configure the number of columns (may be variable from 8 up to 32). Write the name of columns and so on...
By DrawViewElements (); my FIRST line is: m_clcRuleList.DeleteAllItems ();
and then I write them down another time.
And with that you can call the OnDraw easily with an pDoc->UpdateAllViews (NULL); in a Timer with the interval you desire
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
|
|
|
|
|
shir_k wrote: int nIndex = ptrCmdResp->GetItemCount();
ptrCmdResp->RedrawItems(nIndex,nIndex);
Comment out these two statements and see what happens.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
There is no difference
Thanks
|
|
|
|