|
Think about this logically: you need all the records from the file in memory at the same time, so the laws of physics state that you will consume record_count x record_size bytes of memory at minimum. The only alternative is what I suggested earlier, read in only the records you need at any one time. The overhead to do this is unlikely to be great enough to cause you any major problems.
|
|
|
|
|
Hello
I am totally agree with you Mr. macCutchan.
And we were doing like that but now Requirements are changed.
Regards
Yogesh
|
|
|
|
|
yogeshs wrote: but now Requirements are changed
Well you need to look at your design as there is no way you can have this data in memory without it using space in memory!
|
|
|
|
|
yogeshs wrote: Test* obj = new Test();
for(.......)
{
...
...
reading File int obj pointer
And then inserting into map
mapTest.insert(make_pair(string,objTest));
}
because map keep reference to memory allocated to the object, since you deleting the obj afterward the actual memory got deleted and reference in map just point to deleted memory!.
if memory is not constraint you can create copy of memory variable when inserting into map!,however at the time of clearing of map you have to manually delete memory associated with the variables.
"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
|
|
|
|
|
Thnks Alok,But my main constraint is memory here only.
Is there any other idea to erase memory after i use in map?
As you told map keep reference of object pointer.
Then how can i use map as a storage container of class objects.
Is there any other way to store class objects in some STL and then delete tht newed class object.
Bcoz otherwise if we dont delete then heap memory will get full or memory leaks.
Thanks In Advance.
Regards
Yogesh
modified 4-Oct-11 7:53am.
|
|
|
|
|
yogeshs wrote: As you told map keep reference of object pointer.
it's depend on the way you implement the collection class, in your case your container is of string and object pointer.
yogeshs wrote: Then how can i use map as a storage container of class objects.
Is there any other way to store class objects in some STL and then delete tht newed class object.
see if you want anything readily available, it should be present in memory,see if you delete the newly created class-object using new, the object is lost till you have copy of same available for you. there is no way AFAIK to have something with having nothing.
Now, this a design issue not programming issue, so you can relax , design can be created only if i have full requirement otherwise there always flaw in design which can lead to defects
"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
|
|
|
|
|
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!
|
|
|
|
|