|
If you are using your own implementation of a list then we obviously cannot say what it does. I will therefore assume that you are using an existing implementation, such as std::list (you didn't say!).
Every time you insert an item into a list, a new list node will be allocated. This node - depending on te actual implementation - will at least contain one or, more likely, two pointers that are required to maintain the links to the remainder of the list, and the actual data. So, even if your list only holds short values, each node might in fact take 10 bytes (2*sizeof (pointer_type) + 2) to allocate 50 thousand items thus will require half a million bytes of memory.
If your list items are large, requiring 1000 bytes each to store, then each node will be 1000+2*sizeof(pointer_type) in size, and the whole list will require 500 MB of storage.
If your list maintains large objects and you've decided to store them elsewhere you might want to only stor epointers to these items in your list, but even then each list node will store three pointers: two to maintain the list, and one to point to the actual data. On a 32 bit system that would be 12 bytes, or 600 thousand bytes for a list of 50 thousand items.
In short, you're storing information in memory, a lot of it - why are you surprised this takes up memory?
P.S.: according to your question the list takes up more memory than you are comfortable with. This begs some questions:
1. How much memory do you have available (i. e. what does the target system provide)?
2. How large is each indivuidual item?
3. Are these items stored redundantly, i. e. are they being held in several lists at once, or in other sorts of containers?
4. Where do you get the data from (files, media streams, internet, other applications)?
5. Would it be possible to store just one or a few items, process them and store away the results?
6. Have you considered compressing the data - either each node individually, or by storing only the differences to previous items?
modified on Thursday, June 16, 2011 5:02 AM
|
|
|
|
|
That's normal.
You add/create data to a datastructure.
To remove the problem just remove the items from the list ( and be certain to do house-cleaning )
are you doing/allocating/creating your list :
(pseudo code-ish)
int myArray[50000];
for ( int i = 0; i < 50000; i++)
myArray[i] = i;
or
int* myArray = malloc (sizeof(int) * 50000);
for ( int i = 0 i < 50000; i++ )
myArray[i] = i;
or
std::list<int> myList;
for ( unsigned int i = 0; i < 50000; i++ )
myList.push_back( i );
Watched code never compiles.
|
|
|
|
|
what did you expect would happen ?
adding things to memory takes memory.
|
|
|
|
|
Chris Losinger wrote: adding things to memory takes memory.
They never told me that at PC World!
The best things in life are not things.
|
|
|
|
|
Just imagine what you could have done with that knowledge!
|
|
|
|
|
I surprised you got something coherent out of PC world in the first place...
|
|
|
|
|
VCProgrammer wrote: When i insert 50000 item in my list, my application memory starts increasing.
How are you verifying this?
"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
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
Hi, I want to add a bitmap to a button in my DialogBox.
The code is:
case WM_INITDIALOG:
hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_QUIT));
SendMessage(GetDlgItem(hDlg,ID_QUIT),BM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)hBmp);
return (INT_PTR)TRUE;
but why don't work?
|
|
|
|
|
|
but is it possible to add an image with BM_SETIMAGE without ownerdraw button?
|
|
|
|
|
are you setting the BS_BITMAP style when you create the button?
|
|
|
|
|
no because with BS_BITMAP style show bitmap only without text in the button.
I need [Bitmap+Text]
|
|
|
|
|
Member 2965471 wrote: I need [Bitmap+Text]
See here[^] for more details.
The best things in life are not things.
|
|
|
|
|
I know but don't work in that way!
|
|
|
|
|
Member 2965471 wrote: I know but don't work in that way!
I have just tested this and it works OK. You need to ensure that your bitmap is the same size or smaller than your button. Also if you need to show both bitmap and text, then you must ensure that your bitmap is small enough to leave space for the text.
The best things in life are not things.
modified on Thursday, June 16, 2011 9:35 AM
|
|
|
|
|
What is the return value of LoadBitmap function?
|
|
|
|
|
|
Hi,
I've been working with some code that uses a TCP connection for the past few weeks. I have a socket class derived from CAsyncSocket.
Everything works fine initially. I instantiate my manager class which wraps around the socket class and calls connect (via a member pointer to the socket class). I am then able to send a receive data. The problem comes when there is a socket error. For a currently unknown reason, part of my code is causing a socket error. I have yet to find where this is happening but the problem forced me to test out the part of my code which shoudl attempt to recover the connection. It doesn't work, and I can't get things going.
I have overriden OnClose, which calls a method on the manager class (its parent) called OnSocketClose. This calls socket.shutdown(), socket.close() and 'delete socket'. It then sets the pointer to 0. From here, the next time I attempt to send anything down the socket it looks for the socket pointer == 0, to indicate that it should create a pointer to a new socket.
This new socket is created but fails to connect. I have got it to appear connected on a couple of occasions by moving things around but OnConnect doesn't seem to get called and I am unable to send data. The returned value from socket.connect however reports that the socket is already connected if I call socket.connect again, after a short period of time from the first call to connect (socket error 10056).
Apologies if this sounds a little confusing, but I think I have managed to confuse myself... massively
If it will help, I can post code? Just let me know which parts you need to see.
Thanks!
|
|
|
|
|
Thankfully, I have managed to solve this issue so thought I would post the solution in the hope that it might help someone else with the same problem.
The problem (rather annoyingly) came because the socket was being created initially on the main thread, but was later being created again (after the socket was destroyed because of a connection error) on a worker thread. This meant that the On* callbacks weren't being implemented, and so I got no feedback from OnConnect and didn't receive any data because OnReceive was never being called.
As soon as I managed the socket entirely from the main thread, everything was fixed 
|
|
|
|
|
Hey
I have a MFC dialog app that will process the Enter/Return key presses in the keyboard.
Now if the dialog is minimized or hidden behind some other window, it will not be able to process the Return key presses.
Which makes sense considering the keyboard messages are routed to the window with focus.
I want to route all Return/Enter key presses to my MFC dialog irrespective of whether its hidden or minimized.
Is there a way i can do that?
Thanks in advance.
|
|
|
|
|
|
Yes i want to do this, as this is just a sample app.
What kinda keyboard hooks?
Any particular function that i can use?
Any example code?
|
|
|
|
|
HTH KeyBoard Hooks[^]
on side note, you are making your system unstable by using hooks. and as inputs from others posters you are changing default functionality of other application.
|
|
|
|
|
Are you sure you want to do this? ...this sounds like it would create a headache for your users...
|
|
|
|
|
dipuks wrote: I want to route all Return/Enter key presses to my MFC dialog irrespective of whether its hidden or minimized. Is there a way i can do that?
Why would you want/need to do this? After capturing them, are you planning on passing those keystrokes on so that the window with focus will behave as expected?
"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
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|