|
First, when you delete an object using a pointer then other pointers, including the copy you stored in the map, will not be changed - instead they will then point to invalid memory. Trying to use them causes undefined behaviour. In short: don't do that!
Second, don't store pointers, store the objects instead. That way you'll save one pointer entry per entry, and the map will destroy the objects once you remove the entry from the map.
Third, from other comments I've gathered that you cannot actually afford to keep the whole map in memory. If that is the problem, then my best advice is: do not try to program that! Instead, use a database. The only alternative would be to selectively remove rarely used entries from your map and reread them later, when needed. But that would be inefficient, if the file you are reading is not itself indexed in some way. not to mention that such a paging mechanism isn't exactly easy to implement. A database however has these mechanisms, and rereading individual records back into memory later is fast.
|
|
|
|
|
Stefan_Lang wrote: Second, don't store pointers, store the objects instead. That way you'll save one pointer entry per entry, and the map will destroy the objects once you remove the entry from the map.
For discussion sake, if we kept object instead, still it will create copy of original object (see it call copy constructor,if not properly implemented, there can be problem of shallow copy and dangling pointers), however the only advantage i know would be you don't need to worry about destruction as OOPS by heart take responsibility of destroying of object!
Regards
Alok
"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
|
|
|
|
|
You're right, of course, but I deliberately left out these details as they didn't appear to be relevant. There's many ways to deal with this, and the best probably would be to make a map of smart pointers, but that would require even more memory, and since that appears to be the main problem here I didn't bother to suggest it.
|
|
|
|
|
Hi Developers,
Today I ahve faced a strange issue, that my application is gettong crsshed in release exe but not in debug mode.
The scenario is that i am clicking on the items of a tree controls very rapidly. It is searching functionality & top searched (from the user) has given on the tree. Code of click event of that tree is mapped like this
ON_NOTIFY(NM_CLICK, IDC_TREETOPSEARCH, &CRepLiveSearch::OnClickTopSearch)
And the function is here.
UINT uiFlags = 0;
const MSG* pMsg = GetCurrentMessage();
CTreeCtrl* pTreeCtrl = (CTreeCtrl*)GetDlgItem(pNMHDR->idFrom);
CPoint point(pMsg->pt);
pTreeCtrl->ScreenToClient(&point);
HTREEITEM ht = pTreeCtrl->HitTest(point, &uiFlags);
CString szSelWord = m_suggestionTree.GetItemText(ht);
szSelWord = szSelWord.Left(szSelWord.Find('('));
m_edSearch.SetWindowText(szSelWord);
*pResult = 0;
Can u tell me what may be the problem.
Thanks.
Amrit Agrawal.
Software Developer
|
|
|
|
|
Validate the pointers and HTREEITEM
CTreeCtrl* pTreeCtrl = (CTreeCtrl*)GetDlgItem(pNMHDR->idFrom);
if(!pTreeCtrl)
{
}
also
HTREEITEM ht = pTreeCtrl->HitTest(point, &uiFlags);
if (ht != NULL)
{
pTreeCtrl->Select(ht, TVGN_CARET);
}
else
{
}
|
|
|
|
|
|
You should also check that the function prototype for CRepLiveSearch::OnClickTopSearch matches the correct signature.
I had issues in the past where this did not match and would crash in release, but work ok in debug
If you vote me down, my score will only get lower
|
|
|
|
|
Amrit Agr wrote: ...my application is gettong crsshed...
Crashed is such a meaningless term without any context.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi there all, I am totaly new to MFC! I have just found a job that I have been dreaming for... But my boss is asking for an C++/MFC(Dialog) sample that connects to SQL and fill the combobox by the data taken from database (Northwind for example)... I know how to do that in C# part but really I have no idea how in C++. Please can somebody help me???
C++ MFC ado ado.net sql connection
|
|
|
|
|
|
Maybe you shouldnt have answered if you dont have one but thanks again for making me remember how cruel will the world be... By the way, do you really think that you know the meaning of the word "vital"??? Maybe you shouldn't!
|
|
|
|
|
Message Removed
modified 4-Oct-11 15:38pm.
|
|
|
|
|
Didn't you know:
"Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid."
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
So, this is you ha? Thats it???
|
|
|
|
|
ahmed zahmed wrote: ...you spineless snake.
Two posts in and you've already resorted to name-calling. Amazing.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
symeramon wrote: Please can somebody help me???
If I show you this do I get the job?
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Thanks a lot, you are great! but I am sure you'll have better!
|
|
|
|
|
HIRED!
|
|
|
|
|
|
Thanks, you are so kind...
|
|
|
|
|
Even if you do get a sample, and convince the guy to give you a job, you will fail in it very soon because you know nothing about C++ and MFC.
And dont hnink because you know C# you can pick up C++.
You are going to be in a world of pain if you take this job. And you are going to damage your reputation when the boss relises what a dishonest liar you are and sacks you.
Get a job that matches your skills. Or learn new skills.
==============================
Nothing to say.
|
|
|
|
|
My boss knows everything and I have a little knowledge about C++ , also I have 6 applications in business that I've created... Plus, in the job interview I said to my boss that I have no knowledge about mfc but he said ok cause he is not like "some" others (He believed me)... PLEASE STOP CALLING ME LIAR!!! I just wanted a little help!!! WHAT KIND OF PEOPLE YOU ARE???!!!!!!!!!!! You are liars while you resist to remember your past (I mean your first years in business???) You born with laptops???!!
modified 4-Oct-11 7:34am.
|
|
|
|
|
Right, so if your boss is happy to let you learn on the job then sit down at a computer with Visual Studio installed, and the MSDN, and go through the MFC tutorials.
You will learn all about creating apps, adding controls, manipulating data and so on.
==============================
Nothing to say.
|
|
|
|
|
Try to ignore those A-holes. With 8M+ members quite a few are "less than perfect". I think you are very brave to enter the harsh world of C++, MFC and ADO - coming from your C# background. I wish you well.
|
|
|
|
|
Thank you so much for your nice wishes and kindness... Best wishes to you too...
|
|
|
|