Click here to Skip to main content
15,920,468 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: draw lines on desktop help!! Pin
Albert Holguin17-Jun-11 3:43
professionalAlbert Holguin17-Jun-11 3:43 
GeneralRe: draw lines on desktop help!! Pin
so0_lanhlung217-Jun-11 17:41
so0_lanhlung217-Jun-11 17:41 
GeneralRe: draw lines on desktop help!! Pin
Albert Holguin17-Jun-11 20:59
professionalAlbert Holguin17-Jun-11 20:59 
QuestionMemory increases while inserting items in list Pin
VCProgrammer15-Jun-11 21:38
VCProgrammer15-Jun-11 21:38 
AnswerRe: Memory increases while inserting items in list Pin
JV999915-Jun-11 22:16
professionalJV999915-Jun-11 22:16 
GeneralRe: Memory increases while inserting items in list Pin
Stefan_Lang15-Jun-11 23:02
Stefan_Lang15-Jun-11 23:02 
GeneralRe: Memory increases while inserting items in list Pin
JV999915-Jun-11 23:15
professionalJV999915-Jun-11 23:15 
AnswerRe: Memory increases while inserting items in list [modified] Pin
Stefan_Lang15-Jun-11 22:29
Stefan_Lang15-Jun-11 22:29 
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

AnswerRe: Memory increases while inserting items in list Pin
Maximilien15-Jun-11 23:59
Maximilien15-Jun-11 23:59 
AnswerRe: Memory increases while inserting items in list Pin
Chris Losinger16-Jun-11 3:41
professionalChris Losinger16-Jun-11 3:41 
JokeRe: Memory increases while inserting items in list Pin
Richard MacCutchan16-Jun-11 4:54
mveRichard MacCutchan16-Jun-11 4:54 
GeneralRe: Memory increases while inserting items in list Pin
Niklas L16-Jun-11 8:06
Niklas L16-Jun-11 8:06 
GeneralRe: Memory increases while inserting items in list Pin
Rhuros16-Jun-11 22:04
professionalRhuros16-Jun-11 22:04 
QuestionRe: Memory increases while inserting items in list Pin
David Crow16-Jun-11 8:00
David Crow16-Jun-11 8:00 
Question[Win32]Set bitmap to button Pin
Member 296547115-Jun-11 8:14
Member 296547115-Jun-11 8:14 
AnswerRe: [Win32]Set bitmap to button Pin
Chris Losinger15-Jun-11 8:23
professionalChris Losinger15-Jun-11 8:23 
GeneralRe: [Win32]Set bitmap to button Pin
Member 296547115-Jun-11 8:28
Member 296547115-Jun-11 8:28 
GeneralRe: [Win32]Set bitmap to button Pin
Chris Losinger15-Jun-11 8:33
professionalChris Losinger15-Jun-11 8:33 
GeneralRe: [Win32]Set bitmap to button Pin
Member 296547115-Jun-11 9:01
Member 296547115-Jun-11 9:01 
GeneralRe: [Win32]Set bitmap to button Pin
Richard MacCutchan15-Jun-11 21:15
mveRichard MacCutchan15-Jun-11 21:15 
GeneralRe: [Win32]Set bitmap to button Pin
Member 296547115-Jun-11 22:34
Member 296547115-Jun-11 22:34 
GeneralRe: [Win32]Set bitmap to button [modified] Pin
Richard MacCutchan16-Jun-11 3:22
mveRichard MacCutchan16-Jun-11 3:22 
AnswerRe: [Win32]Set bitmap to button Pin
Abhi Lahare15-Jun-11 8:32
Abhi Lahare15-Jun-11 8:32 
GeneralRe: [Win32]Set bitmap to button Pin
Member 296547115-Jun-11 8:35
Member 296547115-Jun-11 8:35 
QuestionCAsyncSocket - Connection Recovery Pin
burns86315-Jun-11 6:31
burns86315-Jun-11 6:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.